Skip to content

Commit

Permalink
Merge pull request hlashbrooke#76 from hlashbrooke/develop
Browse files Browse the repository at this point in the history
Merging WPCS and TravisCI changes
  • Loading branch information
jonathanbossenger authored Jun 29, 2019
2 parents 33a2589 + f5b029e commit c9dc251
Show file tree
Hide file tree
Showing 18 changed files with 956 additions and 572 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node*
vendor*
vendor*
.gitignore
.vscode
.DS_Store
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: php

matrix:
include:
- php: '7.2'
env: SNIFF=1
- php: '7.1'
env: SNIFF=1
allow_failures:
- php: '5.6'
env: SNIFF=1
- php: '7.0'
env: SNIFF=1
- php: 'nightly'
env: SNIFF=1

before_install:
- if [[ "$SNIFF" == "1" ]]; then export PHPCS_DIR=$PWD/vendor/bin; fi
- if [[ "$SNIFF" == "1" ]]; then export SNIFFS_DIR=$PWD/vendor/wp-coding-standards/wpcs; fi
- composer install
- composer update
- ./vendor/bin/phpcs --config-set installed_paths $SNIFFS_DIR
- ./vendor/bin/phpcs -i
- if [[ "$SNIFF" == "1" ]]; then ./vendor/bin/phpcs --config-set installed_paths $SNIFFS_DIR; fi

script:
- export SNIFFS_IGNORE=*/node/*,*/vendor/*,*Gruntfile.js*,*.min.js*,*.min.css*,*.less*
- if [[ "$SNIFF" == "1" ]]; then ./vendor/bin/phpcs -p . --standard=WordPress --ignore=$SNIFFS_IGNORE; fi
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://www.travis-ci.org/wpugph/WordPress-Plugin-Template.svg?branch=master)](https://www.travis-ci.org/wpugph/WordPress-Plugin-Template)

WordPress Plugin Template
=========================

Expand Down Expand Up @@ -27,7 +29,7 @@ As of v3.0 of this template, there are a few libraries built into it that will m

#### Registering a new post type

Using the [post type API](https://github.com/hlashbrooke/WordPress-Plugin-Template/blob/master/includes/lib/class-wordpress-plugin-template-post-type.php) and the wrapper function from the main plugin class you can easily register new post types with one line of code. For exapmle if you wanted to register a `listing` post type then you could do it like this:
Using the [post type API](https://github.com/hlashbrooke/WordPress-Plugin-Template/blob/master/includes/lib/class-wordpress-plugin-template-post-type.php) and the wrapper function from the main plugin class you can easily register new post types with one line of code. For example if you wanted to register a `listing` post type then you could do it like this:

`WordPress_Plugin_Template()->register_post_type( 'listing', __( 'Listings', 'wordpress-plugin-template' ), __( 'Listing', 'wordpress-plugin-template' ) );`

Expand All @@ -45,6 +47,20 @@ Using the [taxonomy API](https://github.com/hlashbrooke/WordPress-Plugin-Templat

This will register a new taxonomy with all the standard settings. If you would like to modify the taxonomy settings you can use the `{$taxonomy}_register_args` filter. See [the WordPress codex page](http://codex.wordpress.org/Function_Reference/register_taxonomy) for all available arguments.

#### Defining your Settings Page Location

Using the filter {base}menu_settings you can define the placement of your settings page. Set the `location` key to `options`, `menu` or `submenu`. When using `submenu` also set the `parent_slug` key to your preferred parent menu, e.g `themes.php`. For example use the following code to let your options page display under the Appearance parent menu.

```php
$settings['location'] = 'submenu';
$settings['parent_slug'] = 'themes.php';
```

See respective codex pages for `location` option defined below:
https://codex.wordpress.org/Function_Reference/add_options_page
https://developer.wordpress.org/reference/functions/add_menu_page/
https://developer.wordpress.org/reference/functions/add_submenu_page/

#### Calling your Options

Using the [Settings API](https://github.com/hlashbrooke/WordPress-Plugin-Template/blob/master/includes/class-wordpress-plugin-template-settings.php) and the wrapper function from the main plugin class you can easily store options from the WP admin like text boxes, radio options, dropdown, etc. You can call the values by using `id` that you have set under the `settings_fields` function. For example you have the `id` - `text_field`, you can call its value by using `get_option('wpt_text_field')`. Take note that by default, this plugin is using a prefix of `wpt_` before the id that you will be calling, you can override that value by changing it under the `__construct` function `$this->base` variable;
Expand Down
1 change: 1 addition & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* phpcs:ignore */
1 change: 1 addition & 0 deletions assets/css/frontend.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* phpcs:ignore */
14 changes: 11 additions & 3 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
jQuery( document ).ready( function ( e ) {

});
/**
* Plugin Template admin js.
*
* @package WordPress Plugin Template/JS
*/

jQuery( document ).ready(
function ( e ) {

}
);
14 changes: 11 additions & 3 deletions assets/js/frontend.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
jQuery( document ).ready( function ( e ) {

});
/**
* Plugin Template frontend js.
*
* @package WordPress Plugin Template/JS
*/

jQuery( document ).ready(
function ( e ) {

}
);
137 changes: 81 additions & 56 deletions assets/js/settings.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,96 @@
jQuery(document).ready(function($) {
/**
* Plugin Template js settings.
*
* @package WordPress Plugin Template/Settings
*/

/***** Colour picker *****/
jQuery( document ).ready(
function ($) {

$('.colorpicker').hide();
$('.colorpicker').each( function() {
$(this).farbtastic( $(this).closest('.color-picker').find('.color') );
});
/***** Colour picker *****/

$('.color').click(function() {
$(this).closest('.color-picker').find('.colorpicker').fadeIn();
});
$( '.colorpicker' ).hide();
$( '.colorpicker' ).each(
function () {
$( this ).farbtastic( $( this ).closest( '.color-picker' ).find( '.color' ) );
}
);

$(document).mousedown(function() {
$('.colorpicker').each(function() {
var display = $(this).css('display');
if ( display == 'block' )
$(this).fadeOut();
});
});
$( '.color' ).click(
function () {
$( this ).closest( '.color-picker' ).find( '.colorpicker' ).fadeIn();
}
);

$( document ).mousedown(
function () {
$( '.colorpicker' ).each(
function () {
var display = $( this ).css( 'display' );
if (display == 'block') {
$( this ).fadeOut();
}
}
);
}
);

/***** Uploading images *****/
/***** Uploading images *****/

var file_frame;
var file_frame;

jQuery.fn.uploadMediaFile = function( button, preview_media ) {
var button_id = button.attr('id');
var field_id = button_id.replace( '_button', '' );
var preview_id = button_id.replace( '_button', '_preview' );
jQuery.fn.uploadMediaFile = function (button, preview_media) {
var button_id = button.attr( 'id' );
var field_id = button_id.replace( '_button', '' );
var preview_id = button_id.replace( '_button', '_preview' );

// If the media frame already exists, reopen it.
if ( file_frame ) {
file_frame.open();
return;
}
// If the media frame already exists, reopen it.
if (file_frame) {
file_frame.open();
return;
}

// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: jQuery( this ).data( 'uploader_title' ),
button: {
text: jQuery( this ).data( 'uploader_button_text' ),
},
multiple: false
});
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media(
{
title: jQuery( this ).data( 'uploader_title' ),
button: {
text: jQuery( this ).data( 'uploader_button_text' ),
},
multiple: false
}
);

// When an image is selected, run a callback.
file_frame.on( 'select', function() {
attachment = file_frame.state().get('selection').first().toJSON();
jQuery("#"+field_id).val(attachment.id);
if( preview_media ) {
jQuery("#"+preview_id).attr('src',attachment.sizes.thumbnail.url);
}
file_frame = false;
});
// When an image is selected, run a callback.
file_frame.on(
'select',
function () {
attachment = file_frame.state().get( 'selection' ).first().toJSON();
jQuery( "#" + field_id ).val( attachment.id );
if (preview_media) {
jQuery( "#" + preview_id ).attr( 'src', attachment.sizes.thumbnail.url );
}
file_frame = false;
}
);

// Finally, open the modal
file_frame.open();
}
// Finally, open the modal.
file_frame.open();
}

jQuery('.image_upload_button').click(function() {
jQuery.fn.uploadMediaFile( jQuery(this), true );
});
jQuery( '.image_upload_button' ).click(
function () {
jQuery.fn.uploadMediaFile( jQuery( this ), true );
}
);

jQuery('.image_delete_button').click(function() {
jQuery(this).closest('td').find( '.image_data_field' ).val( '' );
jQuery(this).closest('td').find( '.image_preview' ).remove();
return false;
});
jQuery( '.image_delete_button' ).click(
function () {
jQuery( this ).closest( 'td' ).find( '.image_data_field' ).val( '' );
jQuery( this ).closest( 'td' ).find( '.image_preview' ).remove();
return false;
}
);

});
}
);
18 changes: 18 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "hlashbrooke/wordpress-plugin-template",
"license": "GPL-2.0-or-later",
"description": "A robust code template for creating a standards-compliant WordPress plugin.",
"keywords": [
"wordpress", "wp", "plugin template"
],
"support": {
"issues": "https://github.com/hlashbrooke/WordPress-Plugin-Template"
},
"require": {
"php": ">=5.4",
"squizlabs/php_codesniffer": "^3.3.1"
},
"require-dev": {
"wp-coding-standards/wpcs": "2.1.*"
}
}
Loading

0 comments on commit c9dc251

Please sign in to comment.