Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nine-2-five committed Oct 4, 2015
0 parents commit 22301b4
Show file tree
Hide file tree
Showing 26 changed files with 2,571 additions and 0 deletions.
96 changes: 96 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* jshint node:true */
module.exports = function( grunt ){
'use strict';

grunt.initConfig({
// setting folder templates
dirs: {
css: 'assets/css',
less: 'assets/css',
js: 'assets/js'
},

// Compile all .less files.
less: {
compile: {
options: {
// These paths are searched for @imports
paths: ['<%= less.css %>/']
},
files: [{
expand: true,
cwd: '<%= dirs.css %>/',
src: [
'*.less',
'!mixins.less'
],
dest: '<%= dirs.css %>/',
ext: '.css'
}]
}
},

// Minify all .css files.
cssmin: {
minify: {
expand: true,
cwd: '<%= dirs.css %>/',
src: ['*.css'],
dest: '<%= dirs.css %>/',
ext: '.css'
}
},

// Minify .js files.
uglify: {
options: {
preserveComments: 'some'
},
jsfiles: {
files: [{
expand: true,
cwd: '<%= dirs.js %>/',
src: [
'*.js',
'!*.min.js',
'!Gruntfile.js',
],
dest: '<%= dirs.js %>/',
ext: '.min.js'
}]
}
},

// Watch changes for assets
watch: {
less: {
files: [
'<%= dirs.less %>/*.less',
],
tasks: ['less', 'cssmin'],
},
js: {
files: [
'<%= dirs.js %>/*js',
'!<%= dirs.js %>/*.min.js'
],
tasks: ['uglify']
}
},

});

// Load NPM tasks to be used here
grunt.loadNpmTasks( 'grunt-contrib-less' );
grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );

// Register tasks
grunt.registerTask( 'default', [
'less',
'cssmin',
'uglify'
]);

};
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
WordPress Plugin Template
=========================

A robust code template for creating a standards-compliant WordPress plugin.


## Why this template?

After writing many WordPress plugins I slowly developed my own coding style and way of doing things - this template is the culmination of what I've learnt along the way. I use this template as a base for any plugin that I start building and I thought it might benefit more people if I shared it around.

## How do I use it?

You can simply copy the files out of this repo and rename everything as you need it, but to make things easier I have included a [shell script](https://github.com/hlashbrooke/am2-facebook-crawlable-comments/blob/master/build-plugin.sh) in this repo that will automatically copy the files to a new folder, remove all traces of the existing git repo, rename everything in the files according to your new plugin name, and initialise a new git repo in the folder if you choose to do so.

### Running the script

You can run the script just like you would run any shell script - it does not take any arguments, so you don't need to worry about that. Once you start the script it will ask for three things:

1. **Plugin name** - this must be the full name of your plugin, with correct capitalisation and spacing.
2. **Destination folder** - this will be the folder where your new plugin will be created - typically this will be your `wp-content/plugins` folder. You can provide a path that is relative to the script, or an absolute path - either will work.
3. **Include Grunt support (y/n)** - if you enter 'y' here then the Grunt files will be included in the new plugin folder.
4. **Initialise new git repo (y/n)** - if you enter 'y' here then a git repo will be initialised in the new plugin folder.

### API functions

As of v3.0 of this template, there are a few libraries built into it that will make a number of common tasks a lot easier. I will expand on these libraries in future versions.

#### Registering a new post type

Using the [post type API](https://github.com/hlashbrooke/am2-facebook-crawlable-comments/blob/master/includes/lib/class-am2-facebook-crawlable-comments-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:

`WordPress_Plugin_Template()->register_post_type( 'listing', __( 'Listings', 'am2-facebook-crawlable-comments' ), __( 'Listing', 'am2-facebook-crawlable-comments' ) );`

*Note that the `WordPress_Plugin_Template()` function name and the `am2-facebook-crawlable-comments` text domain will each be unique to your plugin after you have used the cloning script.*

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

#### Registering a new taxonomy

Using the [taxonomy API](https://github.com/hlashbrooke/am2-facebook-crawlable-comments/blob/master/includes/lib/class-am2-facebook-crawlable-comments-taxonomy.php) and the wrapper function from the main plugin class you can easily register new taxonomies with one line of code. For example if you wanted to register a `location` taxonomy that applies to the `listing` post type then you could do it like this:

`WordPress_Plugin_Template()->register_taxonomy( 'location', __( 'Locations', 'am2-facebook-crawlable-comments' ), __( 'Location', 'am2-facebook-crawlable-comments' ), 'listing' );`

*Note that the `WordPress_Plugin_Template()` function name and the `am2-facebook-crawlable-comments` text domain will each be unique to your plugin after you have used the cloning script.*

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.

## What does this template give me?

This template includes the following features:

+ Plugin headers as required by WordPress & WordPress.org
+ Readme.txt file as required by WordPress.org
+ Main plugin class
+ Full & minified Javascript files
+ Grunt.js support
+ Standard enqueue functions for the dashboard and the frontend
+ A library for easily registering a new post type
+ A library for easily registering a new taxonomy
+ A library for handling common admin functions (including adding meta boxes to any post type, displaying settings fields and display custom fields for posts)
+ A complete and versatile settings class like you see [here](http://www.hughlashbrooke.com/complete-versatile-options-page-class-wordpress-plugin/)
+ A .pot file to make localisation easier
+ Full text of the GPLv2 license

See the [changelog](https://github.com/hlashbrooke/am2-facebook-crawlable-comments/blob/master/changelog.txt) for a complete list of changes as the template develops.

## I've got an idea/fix for the template

If you would like to contribute to this template then please fork it and send a pull request. I'll merge the request if it fits into the goals for the template and credit you in the [changelog](https://github.com/hlashbrooke/am2-facebook-crawlable-comments/blob/master/changelog.txt).

## This template is amazing! How can I ever repay you?

There's no need to credit me in your code for this template, but if you would like to buy me some lunch then you can [donate here](http://www.hughlashbrooke.com/donate).
47 changes: 47 additions & 0 deletions am2-facebook-crawlable-comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/*
* Plugin Name: WordPress Plugin Template
* Version: 1.0
* Plugin URI: http://www.hughlashbrooke.com/
* Description: This is your starter template for your next WordPress plugin.
* Author: Hugh Lashbrooke
* Author URI: http://www.hughlashbrooke.com/
* Requires at least: 4.0
* Tested up to: 4.0
*
* Text Domain: am2-facebook-crawlable-comments
* Domain Path: /lang/
*
* @package WordPress
* @author Hugh Lashbrooke
* @since 1.0.0
*/

if ( ! defined( 'ABSPATH' ) ) exit;

// Load plugin class files
require_once( 'includes/class-am2-facebook-crawlable-comments.php' );
require_once( 'includes/class-am2-facebook-crawlable-comments-settings.php' );

// Load plugin libraries
require_once( 'includes/lib/class-am2-facebook-crawlable-comments-admin-api.php' );
require_once( 'includes/lib/class-am2-facebook-crawlable-comments-post-type.php' );
require_once( 'includes/lib/class-am2-facebook-crawlable-comments-taxonomy.php' );

/**
* Returns the main instance of WordPress_Plugin_Template to prevent the need to use globals.
*
* @since 1.0.0
* @return object WordPress_Plugin_Template
*/
function WordPress_Plugin_Template () {
$instance = WordPress_Plugin_Template::instance( __FILE__, '1.0.0' );

if ( is_null( $instance->settings ) ) {
$instance->settings = WordPress_Plugin_Template_Settings::instance( $instance );
}

return $instance;
}

WordPress_Plugin_Template();
Empty file added assets/css/admin.css
Empty file.
Empty file added assets/css/admin.less
Empty file.
Empty file added assets/css/frontend.css
Empty file.
Empty file added assets/css/frontend.less
Empty file.
3 changes: 3 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jQuery( document ).ready( function ( e ) {

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

});
1 change: 1 addition & 0 deletions assets/js/frontend.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jQuery(document).ready(function(){});
71 changes: 71 additions & 0 deletions assets/js/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
jQuery(document).ready(function($) {

/***** Colour picker *****/

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

$('.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 *****/

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' );

// 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
});

// 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();
}

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;
});

});
1 change: 1 addition & 0 deletions assets/js/settings.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 22301b4

Please sign in to comment.