t push -u origin master

parents
Pipeline #15 skipped
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
\ No newline at end of file
<?php
/*
* Plugin Name: autoshortcoder
* 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: autoshortcoder
* Domain Path: /lang/
*
* @package WordPress
* @author Hugh Lashbrooke
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) exit;
// Load plugin class files
require_once( 'includes/class-autoshortcoder.php' );
require_once( 'includes/class-autoshortcoder-settings.php' );
// Load plugin libraries
require_once( 'includes/lib/class-autoshortcoder-admin-api.php' );
require_once( 'includes/lib/class-autoshortcoder-post-type.php' );
require_once( 'includes/lib/class-autoshortcoder-taxonomy.php' );
/**
* Returns the main instance of autoshortcoder to prevent the need to use globals.
*
* @since 1.0.0
* @return object autoshortcoder
*/
function autoshortcoder () {
$instance = autoshortcoder::instance( __FILE__, '1.0.0' );
if ( is_null( $instance->settings ) ) {
$instance->settings = autoshortcoder_Settings::instance( $instance );
}
return $instance;
}
autoshortcoder();
\ No newline at end of file
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class autoshortcoder_Settings {
/**
* The single instance of autoshortcoder_Settings.
* @var object
* @access private
* @since 1.0.0
*/
private static $_instance = null;
/**
* The main plugin object.
* @var object
* @access public
* @since 1.0.0
*/
public $parent = null;
/**
* Prefix for plugin settings.
* @var string
* @access public
* @since 1.0.0
*/
public $base = '';
/**
* Available settings for plugin.
* @var array
* @access public
* @since 1.0.0
*/
public $settings = array();
public function __construct ( $parent ) {
$this->parent = $parent;
$this->base = 'wpt_';
// Initialise settings
add_action( 'init', array( $this, 'init_settings' ), 11 );
// Register plugin settings
add_action( 'admin_init' , array( $this, 'register_settings' ) );
// Add settings page to menu
add_action( 'admin_menu' , array( $this, 'add_menu_item' ) );
// Add settings link to plugins page
add_filter( 'plugin_action_links_' . plugin_basename( $this->parent->file ) , array( $this, 'add_settings_link' ) );
}
/**
* Initialise settings
* @return void
*/
public function init_settings () {
$this->settings = $this->settings_fields();
}
/**
* Add settings page to admin menu
* @return void
*/
public function add_menu_item () {
$page = add_options_page( __( 'Plugin Settings', 'autoshortcoder' ) , __( 'Plugin Settings', 'autoshortcoder' ) , 'manage_options' , $this->parent->_token . '_settings' , array( $this, 'settings_page' ) );
add_action( 'admin_print_styles-' . $page, array( $this, 'settings_assets' ) );
}
/**
* Load settings JS & CSS
* @return void
*/
public function settings_assets () {
// We're including the farbtastic script & styles here because they're needed for the colour picker
// If you're not including a colour picker field then you can leave these calls out as well as the farbtastic dependency for the wpt-admin-js script below
wp_enqueue_style( 'farbtastic' );
wp_enqueue_script( 'farbtastic' );
// We're including the WP media scripts here because they're needed for the image upload field
// If you're not including an image upload then you can leave this function call out
wp_enqueue_media();
wp_register_script( $this->parent->_token . '-settings-js', $this->parent->assets_url . 'js/settings' . $this->parent->script_suffix . '.js', array( 'farbtastic', 'jquery' ), '1.0.0' );
wp_enqueue_script( $this->parent->_token . '-settings-js' );
}
/**
* Add settings link to plugin list table
* @param array $links Existing links
* @return array Modified links
*/
public function add_settings_link ( $links ) {
$settings_link = '<a href="options-general.php?page=' . $this->parent->_token . '_settings">' . __( 'Settings', 'autoshortcoder' ) . '</a>';
array_push( $links, $settings_link );
return $links;
}
/**
* Build settings fields
* @return array Fields to be displayed on settings page
*/
private function settings_fields () {
$settings['standard'] = array(
'title' => __( 'Standard', 'autoshortcoder' ),
'description' => __( 'These are fairly standard form input fields.', 'autoshortcoder' ),
'fields' => array(
array(
'id' => 'text_field',
'label' => __( 'Some Text' , 'autoshortcoder' ),
'description' => __( 'This is a standard text field.', 'autoshortcoder' ),
'type' => 'text',
'default' => '',
'placeholder' => __( 'Placeholder text', 'autoshortcoder' )
),
array(
'id' => 'password_field',
'label' => __( 'A Password' , 'autoshortcoder' ),
'description' => __( 'This is a standard password field.', 'autoshortcoder' ),
'type' => 'password',
'default' => '',
'placeholder' => __( 'Placeholder text', 'autoshortcoder' )
),
array(
'id' => 'secret_text_field',
'label' => __( 'Some Secret Text' , 'autoshortcoder' ),
'description' => __( 'This is a secret text field - any data saved here will not be displayed after the page has reloaded, but it will be saved.', 'autoshortcoder' ),
'type' => 'text_secret',
'default' => '',
'placeholder' => __( 'Placeholder text', 'autoshortcoder' )
),
array(
'id' => 'text_block',
'label' => __( 'A Text Block' , 'autoshortcoder' ),
'description' => __( 'This is a standard text area.', 'autoshortcoder' ),
'type' => 'textarea',
'default' => '',
'placeholder' => __( 'Placeholder text for this textarea', 'autoshortcoder' )
),
array(
'id' => 'single_checkbox',
'label' => __( 'An Option', 'autoshortcoder' ),
'description' => __( 'A standard checkbox - if you save this option as checked then it will store the option as \'on\', otherwise it will be an empty string.', 'autoshortcoder' ),
'type' => 'checkbox',
'default' => ''
),
array(
'id' => 'select_box',
'label' => __( 'A Select Box', 'autoshortcoder' ),
'description' => __( 'A standard select box.', 'autoshortcoder' ),
'type' => 'select',
'options' => array( 'drupal' => 'Drupal', 'joomla' => 'Joomla', 'wordpress' => 'WordPress' ),
'default' => 'wordpress'
),
array(
'id' => 'radio_buttons',
'label' => __( 'Some Options', 'autoshortcoder' ),
'description' => __( 'A standard set of radio buttons.', 'autoshortcoder' ),
'type' => 'radio',
'options' => array( 'superman' => 'Superman', 'batman' => 'Batman', 'ironman' => 'Iron Man' ),
'default' => 'batman'
),
array(
'id' => 'multiple_checkboxes',
'label' => __( 'Some Items', 'autoshortcoder' ),
'description' => __( 'You can select multiple items and they will be stored as an array.', 'autoshortcoder' ),
'type' => 'checkbox_multi',
'options' => array( 'square' => 'Square', 'circle' => 'Circle', 'rectangle' => 'Rectangle', 'triangle' => 'Triangle' ),
'default' => array( 'circle', 'triangle' )
)
)
);
$settings['extra'] = array(
'title' => __( 'Extra', 'autoshortcoder' ),
'description' => __( 'These are some extra input fields that maybe aren\'t as common as the others.', 'autoshortcoder' ),
'fields' => array(
array(
'id' => 'number_field',
'label' => __( 'A Number' , 'autoshortcoder' ),
'description' => __( 'This is a standard number field - if this field contains anything other than numbers then the form will not be submitted.', 'autoshortcoder' ),
'type' => 'number',
'default' => '',
'placeholder' => __( '42', 'autoshortcoder' )
),
array(
'id' => 'colour_picker',
'label' => __( 'Pick a colour', 'autoshortcoder' ),
'description' => __( 'This uses WordPress\' built-in colour picker - the option is stored as the colour\'s hex code.', 'autoshortcoder' ),
'type' => 'color',
'default' => '#21759B'
),
array(
'id' => 'an_image',
'label' => __( 'An Image' , 'autoshortcoder' ),
'description' => __( 'This will upload an image to your media library and store the attachment ID in the option field. Once you have uploaded an imge the thumbnail will display above these buttons.', 'autoshortcoder' ),
'type' => 'image',
'default' => '',
'placeholder' => ''
),
array(
'id' => 'multi_select_box',
'label' => __( 'A Multi-Select Box', 'autoshortcoder' ),
'description' => __( 'A standard multi-select box - the saved data is stored as an array.', 'autoshortcoder' ),
'type' => 'select_multi',
'options' => array( 'linux' => 'Linux', 'mac' => 'Mac', 'windows' => 'Windows' ),
'default' => array( 'linux' )
)
)
);
$settings = apply_filters( $this->parent->_token . '_settings_fields', $settings );
return $settings;
}
/**
* Register plugin settings
* @return void
*/
public function register_settings () {
if ( is_array( $this->settings ) ) {
// Check posted/selected tab
$current_section = '';
if ( isset( $_POST['tab'] ) && $_POST['tab'] ) {
$current_section = $_POST['tab'];
} else {
if ( isset( $_GET['tab'] ) && $_GET['tab'] ) {
$current_section = $_GET['tab'];
}
}
foreach ( $this->settings as $section => $data ) {
if ( $current_section && $current_section != $section ) continue;
// Add section to page
add_settings_section( $section, $data['title'], array( $this, 'settings_section' ), $this->parent->_token . '_settings' );
foreach ( $data['fields'] as $field ) {
// Validation callback for field
$validation = '';
if ( isset( $field['callback'] ) ) {
$validation = $field['callback'];
}
// Register field
$option_name = $this->base . $field['id'];
register_setting( $this->parent->_token . '_settings', $option_name, $validation );
// Add field to page
add_settings_field( $field['id'], $field['label'], array( $this->parent->admin, 'display_field' ), $this->parent->_token . '_settings', $section, array( 'field' => $field, 'prefix' => $this->base ) );
}
if ( ! $current_section ) break;
}
}
}
public function settings_section ( $section ) {
$html = '<p> ' . $this->settings[ $section['id'] ]['description'] . '</p>' . "\n";
echo $html;
}
/**
* Load settings page content
* @return void
*/
public function settings_page () {
// Build page HTML
$html = '<div class="wrap" id="' . $this->parent->_token . '_settings">' . "\n";
$html .= '<h2>' . __( 'Plugin Settings' , 'autoshortcoder' ) . '</h2>' . "\n";
$tab = '';
if ( isset( $_GET['tab'] ) && $_GET['tab'] ) {
$tab .= $_GET['tab'];
}
// Show page tabs
if ( is_array( $this->settings ) && 1 < count( $this->settings ) ) {
$html .= '<h2 class="nav-tab-wrapper">' . "\n";
$c = 0;
foreach ( $this->settings as $section => $data ) {
// Set tab class
$class = 'nav-tab';
if ( ! isset( $_GET['tab'] ) ) {
if ( 0 == $c ) {
$class .= ' nav-tab-active';
}
} else {
if ( isset( $_GET['tab'] ) && $section == $_GET['tab'] ) {
$class .= ' nav-tab-active';
}
}
// Set tab link
$tab_link = add_query_arg( array( 'tab' => $section ) );
if ( isset( $_GET['settings-updated'] ) ) {
$tab_link = remove_query_arg( 'settings-updated', $tab_link );
}
// Output tab
$html .= '<a href="' . $tab_link . '" class="' . esc_attr( $class ) . '">' . esc_html( $data['title'] ) . '</a>' . "\n";
++$c;
}
$html .= '</h2>' . "\n";
}
$html .= '<form method="post" action="options.php" enctype="multipart/form-data">' . "\n";
// Get settings fields
ob_start();
settings_fields( $this->parent->_token . '_settings' );
do_settings_sections( $this->parent->_token . '_settings' );
$html .= ob_get_clean();
$html .= '<p class="submit">' . "\n";
$html .= '<input type="hidden" name="tab" value="' . esc_attr( $tab ) . '" />' . "\n";
$html .= '<input name="Submit" type="submit" class="button-primary" value="' . esc_attr( __( 'Save Settings' , 'autoshortcoder' ) ) . '" />' . "\n";
$html .= '</p>' . "\n";
$html .= '</form>' . "\n";
$html .= '</div>' . "\n";
echo $html;
}
/**
* Main autoshortcoder_Settings Instance
*
* Ensures only one instance of autoshortcoder_Settings is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @see autoshortcoder()
* @return Main autoshortcoder_Settings instance
*/
public static function instance ( $parent ) {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self( $parent );
}
return self::$_instance;
} // End instance()
/**
* Cloning is forbidden.
*
* @since 1.0.0
*/
public function __clone () {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), $this->parent->_version );
} // End __clone()
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup () {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), $this->parent->_version );
} // End __wakeup()
}
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class autoshortcoder_Settings {
/**
* The single instance of autoshortcoder_Settings.
* @var object
* @access private
* @since 1.0.0
*/
private static $_instance = null;
/**
* The main plugin object.
* @var object
* @access public
* @since 1.0.0
*/
public $parent = null;
/**
* Prefix for plugin settings.
* @var string
* @access public
* @since 1.0.0
*/
public $base = '';
/**
* Available settings for plugin.
* @var array
* @access public
* @since 1.0.0
*/
public $settings = array();
public function __construct ( $parent ) {
$this->parent = $parent;
$this->base = 'wpt_';
// Initialise settings
add_action( 'init', array( $this, 'init_settings' ), 11 );
// Register plugin settings
add_action( 'admin_init' , array( $this, 'register_settings' ) );
// Add settings page to menu
add_action( 'admin_menu' , array( $this, 'add_menu_item' ) );
// Add settings link to plugins page
add_filter( 'plugin_action_links_' . plugin_basename( $this->parent->file ) , array( $this, 'add_settings_link' ) );
}
/**
* Initialise settings
* @return void
*/
public function init_settings () {
$this->settings = $this->settings_fields();
}
/**
* Add settings page to admin menu
* @return void
*/
public function add_menu_item () {
$page = add_options_page( __( 'Plugin Settings', 'autoshortcoder' ) , __( 'Plugin Settings', 'autoshortcoder' ) , 'manage_options' , $this->parent->_token . '_settings' , array( $this, 'settings_page' ) );
add_action( 'admin_print_styles-' . $page, array( $this, 'settings_assets' ) );
}
/**
* Load settings JS & CSS
* @return void
*/
public function settings_assets () {
// We're including the farbtastic script & styles here because they're needed for the colour picker
// If you're not including a colour picker field then you can leave these calls out as well as the farbtastic dependency for the wpt-admin-js script below
wp_enqueue_style( 'farbtastic' );
wp_enqueue_script( 'farbtastic' );
// We're including the WP media scripts here because they're needed for the image upload field
// If you're not including an image upload then you can leave this function call out
wp_enqueue_media();
wp_register_script( $this->parent->_token . '-settings-js', $this->parent->assets_url . 'js/settings' . $this->parent->script_suffix . '.js', array( 'farbtastic', 'jquery' ), '1.0.0' );
wp_enqueue_script( $this->parent->_token . '-settings-js' );
}
/**
* Add settings link to plugin list table
* @param array $links Existing links
* @return array Modified links
*/
public function add_settings_link ( $links ) {
$settings_link = '<a href="options-general.php?page=' . $this->parent->_token . '_settings">' . __( 'Settings', 'autoshortcoder' ) . '</a>';
array_push( $links, $settings_link );
return $links;
}
/**
* Build settings fields
* @return array Fields to be displayed on settings page
*/
private function settings_fields () {
$settings['standard'] = array(
'title' => __( 'Standard', 'autoshortcoder' ),
'description' => __( 'These are fairly standard form input fields.', 'autoshortcoder' ),
'fields' => array(
array(
'id' => 'text_field',
'label' => __( 'Some Text' , 'autoshortcoder' ),
'description' => __( 'This is a standard text field.', 'autoshortcoder' ),
'type' => 'text',
'default' => '',
'placeholder' => __( 'Placeholder text', 'autoshortcoder' )
),
array(
'id' => 'password_field',
'label' => __( 'A Password' , 'autoshortcoder' ),
'description' => __( 'This is a standard password field.', 'autoshortcoder' ),
'type' => 'password',
'default' => '',
'placeholder' => __( 'Placeholder text', 'autoshortcoder' )
),
array(
'id' => 'secret_text_field',
'label' => __( 'Some Secret Text' , 'autoshortcoder' ),
'description' => __( 'This is a secret text field - any data saved here will not be displayed after the page has reloaded, but it will be saved.', 'autoshortcoder' ),
'type' => 'text_secret',
'default' => '',
'placeholder' => __( 'Placeholder text', 'autoshortcoder' )
),
array(
'id' => 'text_block',
'label' => __( 'A Text Block' , 'autoshortcoder' ),
'description' => __( 'This is a standard text area.', 'autoshortcoder' ),
'type' => 'textarea',
'default' => '',
'placeholder' => __( 'Placeholder text for this textarea', 'autoshortcoder' )
),
array(
'id' => 'single_checkbox',
'label' => __( 'An Option', 'autoshortcoder' ),
'description' => __( 'A standard checkbox - if you save this option as checked then it will store the option as \'on\', otherwise it will be an empty string.', 'autoshortcoder' ),
'type' => 'checkbox',
'default' => ''
),
array(
'id' => 'select_box',
'label' => __( 'A Select Box', 'autoshortcoder' ),
'description' => __( 'A standard select box.', 'autoshortcoder' ),
'type' => 'select',
'options' => array( 'drupal' => 'Drupal', 'joomla' => 'Joomla', 'wordpress' => 'WordPress' ),
'default' => 'wordpress'
),
array(
'id' => 'radio_buttons',
'label' => __( 'Some Options', 'autoshortcoder' ),
'description' => __( 'A standard set of radio buttons.', 'autoshortcoder' ),
'type' => 'radio',
'options' => array( 'superman' => 'Superman', 'batman' => 'Batman', 'ironman' => 'Iron Man' ),
'default' => 'batman'
),
array(
'id' => 'multiple_checkboxes',
'label' => __( 'Some Items', 'autoshortcoder' ),
'description' => __( 'You can select multiple items and they will be stored as an array.', 'autoshortcoder' ),
'type' => 'checkbox_multi',
'options' => array( 'square' => 'Square', 'circle' => 'Circle', 'rectangle' => 'Rectangle', 'triangle' => 'Triangle' ),
'default' => array( 'circle', 'triangle' )
)
)
);
$settings['extra'] = array(
'title' => __( 'Extra', 'autoshortcoder' ),
'description' => __( 'These are some extra input fields that maybe aren\'t as common as the others.', 'autoshortcoder' ),
'fields' => array(
array(
'id' => 'number_field',
'label' => __( 'A Number' , 'autoshortcoder' ),
'description' => __( 'This is a standard number field - if this field contains anything other than numbers then the form will not be submitted.', 'autoshortcoder' ),
'type' => 'number',
'default' => '',
'placeholder' => __( '42', 'autoshortcoder' )
),
array(
'id' => 'colour_picker',
'label' => __( 'Pick a colour', 'autoshortcoder' ),
'description' => __( 'This uses WordPress\' built-in colour picker - the option is stored as the colour\'s hex code.', 'autoshortcoder' ),
'type' => 'color',
'default' => '#21759B'
),
array(
'id' => 'an_image',
'label' => __( 'An Image' , 'autoshortcoder' ),
'description' => __( 'This will upload an image to your media library and store the attachment ID in the option field. Once you have uploaded an imge the thumbnail will display above these buttons.', 'autoshortcoder' ),
'type' => 'image',
'default' => '',
'placeholder' => ''
),
array(
'id' => 'multi_select_box',
'label' => __( 'A Multi-Select Box', 'autoshortcoder' ),
'description' => __( 'A standard multi-select box - the saved data is stored as an array.', 'autoshortcoder' ),
'type' => 'select_multi',
'options' => array( 'linux' => 'Linux', 'mac' => 'Mac', 'windows' => 'Windows' ),
'default' => array( 'linux' )
)
)
);
$settings = apply_filters( $this->parent->_token . '_settings_fields', $settings );
return $settings;
}
/**
* Register plugin settings
* @return void
*/
public function register_settings () {
if ( is_array( $this->settings ) ) {
// Check posted/selected tab
$current_section = '';
if ( isset( $_POST['tab'] ) && $_POST['tab'] ) {
$current_section = $_POST['tab'];
} else {
if ( isset( $_GET['tab'] ) && $_GET['tab'] ) {
$current_section = $_GET['tab'];
}
}
foreach ( $this->settings as $section => $data ) {
if ( $current_section && $current_section != $section ) continue;
// Add section to page
add_settings_section( $section, $data['title'], array( $this, 'settings_section' ), $this->parent->_token . '_settings' );
foreach ( $data['fields'] as $field ) {
// Validation callback for field
$validation = '';
if ( isset( $field['callback'] ) ) {
$validation = $field['callback'];
}
// Register field
$option_name = $this->base . $field['id'];
register_setting( $this->parent->_token . '_settings', $option_name, $validation );
// Add field to page
add_settings_field( $field['id'], $field['label'], array( $this->parent->admin, 'display_field' ), $this->parent->_token . '_settings', $section, array( 'field' => $field, 'prefix' => $this->base ) );
}
if ( ! $current_section ) break;
}
}
}
public function settings_section ( $section ) {
$html = '<p> ' . $this->settings[ $section['id'] ]['description'] . '</p>' . "\n";
echo $html;
}
/**
* Load settings page content
* @return void
*/
public function settings_page () {
// Build page HTML
$html = '<div class="wrap" id="' . $this->parent->_token . '_settings">' . "\n";
$html .= '<h2>' . __( 'Plugin Settings' , 'autoshortcoder' ) . '</h2>' . "\n";
$tab = '';
if ( isset( $_GET['tab'] ) && $_GET['tab'] ) {
$tab .= $_GET['tab'];
}
// Show page tabs
if ( is_array( $this->settings ) && 1 < count( $this->settings ) ) {
$html .= '<h2 class="nav-tab-wrapper">' . "\n";
$c = 0;
foreach ( $this->settings as $section => $data ) {
// Set tab class
$class = 'nav-tab';
if ( ! isset( $_GET['tab'] ) ) {
if ( 0 == $c ) {
$class .= ' nav-tab-active';
}
} else {
if ( isset( $_GET['tab'] ) && $section == $_GET['tab'] ) {
$class .= ' nav-tab-active';
}
}
// Set tab link
$tab_link = add_query_arg( array( 'tab' => $section ) );
if ( isset( $_GET['settings-updated'] ) ) {
$tab_link = remove_query_arg( 'settings-updated', $tab_link );
}
// Output tab
$html .= '<a href="' . $tab_link . '" class="' . esc_attr( $class ) . '">' . esc_html( $data['title'] ) . '</a>' . "\n";
++$c;
}
$html .= '</h2>' . "\n";
}
$html .= '<form method="post" action="options.php" enctype="multipart/form-data">' . "\n";
// Get settings fields
ob_start();
settings_fields( $this->parent->_token . '_settings' );
do_settings_sections( $this->parent->_token . '_settings' );
$html .= ob_get_clean();
$html .= '<p class="submit">' . "\n";
$html .= '<input type="hidden" name="tab" value="' . esc_attr( $tab ) . '" />' . "\n";
$html .= '<input name="Submit" type="submit" class="button-primary" value="' . esc_attr( __( 'Save Settings' , 'autoshortcoder' ) ) . '" />' . "\n";
$html .= '</p>' . "\n";
$html .= '</form>' . "\n";
$html .= '</div>' . "\n";
echo $html;
}
/**
* Main autoshortcoder_Settings Instance
*
* Ensures only one instance of autoshortcoder_Settings is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @see autoshortcoder()
* @return Main autoshortcoder_Settings instance
*/
public static function instance ( $parent ) {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self( $parent );
}
return self::$_instance;
} // End instance()
/**
* Cloning is forbidden.
*
* @since 1.0.0
*/
public function __clone () {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), $this->parent->_version );
} // End __clone()
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup () {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), $this->parent->_version );
} // End __wakeup()
}
\ No newline at end of file
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class autoshortcoder {
/**
* The single instance of autoshortcoder.
* @var object
* @access private
* @since 1.0.0
*/
private static $_instance = null;
/**
* Settings class object
* @var object
* @access public
* @since 1.0.0
*/
public $settings = null;
/**
* The version number.
* @var string
* @access public
* @since 1.0.0
*/
public $_version;
/**
* The token.
* @var string
* @access public
* @since 1.0.0
*/
public $_token;
/**
* The main plugin file.
* @var string
* @access public
* @since 1.0.0
*/
public $file;
/**
* The main plugin directory.
* @var string
* @access public
* @since 1.0.0
*/
public $dir;
/**
* The plugin assets directory.
* @var string
* @access public
* @since 1.0.0
*/
public $assets_dir;
/**
* The plugin assets URL.
* @var string
* @access public
* @since 1.0.0
*/
public $assets_url;
/**
* Suffix for Javascripts.
* @var string
* @access public
* @since 1.0.0
*/
public $script_suffix;
/**
* Constructor function.
* @access public
* @since 1.0.0
* @return void
*/
public function __construct ( $file = '', $version = '1.0.0' ) {
$this->_version = $version;
$this->_token = 'autoshortcoder';
// Load plugin environment variables
$this->file = $file;
$this->dir = dirname( $this->file );
$this->assets_dir = trailingslashit( $this->dir ) . 'assets';
$this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $this->file ) ) );
$this->script_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
register_activation_hook( $this->file, array( $this, 'install' ) );
// Load frontend JS & CSS
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ), 10 );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10 );
// Load admin JS & CSS
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 10, 1 );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ), 10, 1 );
// Load API for generic admin functions
if ( is_admin() ) {
$this->admin = new autoshortcoder_Admin_API();
}
// Handle localisation
$this->load_plugin_textdomain();
add_action( 'init', array( $this, 'load_localisation' ), 0 );
} // End __construct ()
/**
* Wrapper function to register a new post type
* @param string $post_type Post type name
* @param string $plural Post type item plural name
* @param string $single Post type item single name
* @param string $description Description of post type
* @return object Post type class object
*/
public function register_post_type ( $post_type = '', $plural = '', $single = '', $description = '', $options = array() ) {
if ( ! $post_type || ! $plural || ! $single ) return;
$post_type = new autoshortcoder_Post_Type( $post_type, $plural, $single, $description, $options );
return $post_type;
}
/**
* Wrapper function to register a new taxonomy
* @param string $taxonomy Taxonomy name
* @param string $plural Taxonomy single name
* @param string $single Taxonomy plural name
* @param array $post_types Post types to which this taxonomy applies
* @return object Taxonomy class object
*/
public function register_taxonomy ( $taxonomy = '', $plural = '', $single = '', $post_types = array(), $taxonomy_args = array() ) {
if ( ! $taxonomy || ! $plural || ! $single ) return;
$taxonomy = new autoshortcoder_Taxonomy( $taxonomy, $plural, $single, $post_types, $taxonomy_args );
return $taxonomy;
}
/**
* Load frontend CSS.
* @access public
* @since 1.0.0
* @return void
*/
public function enqueue_styles () {
wp_register_style( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'css/frontend.css', array(), $this->_version );
wp_enqueue_style( $this->_token . '-frontend' );
} // End enqueue_styles ()
/**
* Load frontend Javascript.
* @access public
* @since 1.0.0
* @return void
*/
public function enqueue_scripts () {
wp_register_script( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'js/frontend' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version );
wp_enqueue_script( $this->_token . '-frontend' );
} // End enqueue_scripts ()
/**
* Load admin CSS.
* @access public
* @since 1.0.0
* @return void
*/
public function admin_enqueue_styles ( $hook = '' ) {
wp_register_style( $this->_token . '-admin', esc_url( $this->assets_url ) . 'css/admin.css', array(), $this->_version );
wp_enqueue_style( $this->_token . '-admin' );
} // End admin_enqueue_styles ()
/**
* Load admin Javascript.
* @access public
* @since 1.0.0
* @return void
*/
public function admin_enqueue_scripts ( $hook = '' ) {
wp_register_script( $this->_token . '-admin', esc_url( $this->assets_url ) . 'js/admin' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version );
wp_enqueue_script( $this->_token . '-admin' );
} // End admin_enqueue_scripts ()
/**
* Load plugin localisation
* @access public
* @since 1.0.0
* @return void
*/
public function load_localisation () {
load_plugin_textdomain( 'autoshortcoder', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
} // End load_localisation ()
/**
* Load plugin textdomain
* @access public
* @since 1.0.0
* @return void
*/
public function load_plugin_textdomain () {
$domain = 'autoshortcoder';
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
} // End load_plugin_textdomain ()
/**
* Main autoshortcoder Instance
*
* Ensures only one instance of autoshortcoder is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @see autoshortcoder()
* @return Main autoshortcoder instance
*/
public static function instance ( $file = '', $version = '1.0.0' ) {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self( $file, $version );
}
return self::$_instance;
} // End instance ()
/**
* Cloning is forbidden.
*
* @since 1.0.0
*/
public function __clone () {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), $this->_version );
} // End __clone ()
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup () {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), $this->_version );
} // End __wakeup ()
/**
* Installation. Runs on activation.
* @access public
* @since 1.0.0
* @return void
*/
public function install () {
$this->_log_version_number();
} // End install ()
/**
* Log the plugin version number.
* @access public
* @since 1.0.0
* @return void
*/
private function _log_version_number () {
update_option( $this->_token . '_version', $this->_version );
} // End _log_version_number ()
}
\ No newline at end of file
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class autoshortcoder_Admin_API {
/**
* Constructor function
*/
public function __construct () {
add_action( 'save_post', array( $this, 'save_meta_boxes' ), 10, 1 );
}
/**
* Generate HTML for displaying fields
* @param array $field Field data
* @param boolean $echo Whether to echo the field HTML or return it
* @return void
*/
public function display_field ( $data = array(), $post = false, $echo = true ) {
// Get field info
if ( isset( $data['field'] ) ) {
$field = $data['field'];
} else {
$field = $data;
}
// Check for prefix on option name
$option_name = '';
if ( isset( $data['prefix'] ) ) {
$option_name = $data['prefix'];
}
// Get saved data
$data = '';
if ( $post ) {
// Get saved field data
$option_name .= $field['id'];
$option = get_post_meta( $post->ID, $field['id'], true );
// Get data to display in field
if ( isset( $option ) ) {
$data = $option;
}
} else {
// Get saved option
$option_name .= $field['id'];
$option = get_option( $option_name );
// Get data to display in field
if ( isset( $option ) ) {
$data = $option;
}
}
// Show default data if no option saved and default is supplied
if ( $data === false && isset( $field['default'] ) ) {
$data = $field['default'];
} elseif ( $data === false ) {
$data = '';
}
$html = '';
switch( $field['type'] ) {
case 'text':
case 'url':
case 'email':
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="text" name="' . esc_attr( $option_name ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . esc_attr( $data ) . '" />' . "\n";
break;
case 'password':
case 'number':
case 'hidden':
$min = '';
if ( isset( $field['min'] ) ) {
$min = ' min="' . esc_attr( $field['min'] ) . '"';
}
$max = '';
if ( isset( $field['max'] ) ) {
$max = ' max="' . esc_attr( $field['max'] ) . '"';
}
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . esc_attr( $field['type'] ) . '" name="' . esc_attr( $option_name ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . esc_attr( $data ) . '"' . $min . '' . $max . '/>' . "\n";
break;
case 'text_secret':
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="text" name="' . esc_attr( $option_name ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="" />' . "\n";
break;
case 'textarea':
$html .= '<textarea id="' . esc_attr( $field['id'] ) . '" rows="5" cols="50" name="' . esc_attr( $option_name ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '">' . $data . '</textarea><br/>'. "\n";
break;
case 'checkbox':
$checked = '';
if ( $data && 'on' == $data ) {
$checked = 'checked="checked"';
}
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . esc_attr( $field['type'] ) . '" name="' . esc_attr( $option_name ) . '" ' . $checked . '/>' . "\n";
break;
case 'checkbox_multi':
foreach ( $field['options'] as $k => $v ) {
$checked = false;
if ( in_array( $k, $data ) ) {
$checked = true;
}
$html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '" class="checkbox_multi"><input type="checkbox" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $option_name ) . '[]" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" /> ' . $v . '</label> ';
}
break;
case 'radio':
foreach ( $field['options'] as $k => $v ) {
$checked = false;
if ( $k == $data ) {
$checked = true;
}
$html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="radio" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $option_name ) . '" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" /> ' . $v . '</label> ';
}
break;
case 'select':
$html .= '<select name="' . esc_attr( $option_name ) . '" id="' . esc_attr( $field['id'] ) . '">';
foreach ( $field['options'] as $k => $v ) {
$selected = false;
if ( $k == $data ) {
$selected = true;
}
$html .= '<option ' . selected( $selected, true, false ) . ' value="' . esc_attr( $k ) . '">' . $v . '</option>';
}
$html .= '</select> ';
break;
case 'select_multi':
$html .= '<select name="' . esc_attr( $option_name ) . '[]" id="' . esc_attr( $field['id'] ) . '" multiple="multiple">';
foreach ( $field['options'] as $k => $v ) {
$selected = false;
if ( in_array( $k, $data ) ) {
$selected = true;
}
$html .= '<option ' . selected( $selected, true, false ) . ' value="' . esc_attr( $k ) . '">' . $v . '</option>';
}
$html .= '</select> ';
break;
case 'image':
$image_thumb = '';
if ( $data ) {
$image_thumb = wp_get_attachment_thumb_url( $data );
}
$html .= '<img id="' . $option_name . '_preview" class="image_preview" src="' . $image_thumb . '" /><br/>' . "\n";
$html .= '<input id="' . $option_name . '_button" type="button" data-uploader_title="' . __( 'Upload an image' , 'autoshortcoder' ) . '" data-uploader_button_text="' . __( 'Use image' , 'autoshortcoder' ) . '" class="image_upload_button button" value="'. __( 'Upload new image' , 'autoshortcoder' ) . '" />' . "\n";
$html .= '<input id="' . $option_name . '_delete" type="button" class="image_delete_button button" value="'. __( 'Remove image' , 'autoshortcoder' ) . '" />' . "\n";
$html .= '<input id="' . $option_name . '" class="image_data_field" type="hidden" name="' . $option_name . '" value="' . $data . '"/><br/>' . "\n";
break;
case 'color':
?><div class="color-picker" style="position:relative;">
<input type="text" name="<?php esc_attr_e( $option_name ); ?>" class="color" value="<?php esc_attr_e( $data ); ?>" />
<div style="position:absolute;background:#FFF;z-index:99;border-radius:100%;" class="colorpicker"></div>
</div>
<?php
break;
}
switch( $field['type'] ) {
case 'checkbox_multi':
case 'radio':
case 'select_multi':
$html .= '<br/><span class="description">' . $field['description'] . '</span>';
break;
default:
if ( ! $post ) {
$html .= '<label for="' . esc_attr( $field['id'] ) . '">' . "\n";
}
$html .= '<span class="description">' . $field['description'] . '</span>' . "\n";
if ( ! $post ) {
$html .= '</label>' . "\n";
}
break;
}
if ( ! $echo ) {
return $html;
}
echo $html;
}
/**
* Validate form field
* @param string $data Submitted value
* @param string $type Type of field to validate
* @return string Validated value
*/
public function validate_field ( $data = '', $type = 'text' ) {
switch( $type ) {
case 'text': $data = esc_attr( $data ); break;
case 'url': $data = esc_url( $data ); break;
case 'email': $data = is_email( $data ); break;
}
return $data;
}
/**
* Add meta box to the dashboard
* @param string $id Unique ID for metabox
* @param string $title Display title of metabox
* @param array $post_types Post types to which this metabox applies
* @param string $context Context in which to display this metabox ('advanced' or 'side')
* @param string $priority Priority of this metabox ('default', 'low' or 'high')
* @param array $callback_args Any axtra arguments that will be passed to the display function for this metabox
* @return void
*/
public function add_meta_box ( $id = '', $title = '', $post_types = array(), $context = 'advanced', $priority = 'default', $callback_args = null ) {
// Get post type(s)
if ( ! is_array( $post_types ) ) {
$post_types = array( $post_types );
}
// Generate each metabox
foreach ( $post_types as $post_type ) {
add_meta_box( $id, $title, array( $this, 'meta_box_content' ), $post_type, $context, $priority, $callback_args );
}
}
/**
* Display metabox content
* @param object $post Post object
* @param array $args Arguments unique to this metabox
* @return void
*/
public function meta_box_content ( $post, $args ) {
$fields = apply_filters( $post->post_type . '_custom_fields', array(), $post->post_type );
if ( ! is_array( $fields ) || 0 == count( $fields ) ) return;
echo '<div class="custom-field-panel">' . "\n";
foreach ( $fields as $field ) {
if ( ! isset( $field['metabox'] ) ) continue;
if ( ! is_array( $field['metabox'] ) ) {
$field['metabox'] = array( $field['metabox'] );
}
if ( in_array( $args['id'], $field['metabox'] ) ) {
$this->display_meta_box_field( $field, $post );
}
}
echo '</div>' . "\n";
}
/**
* Dispay field in metabox
* @param array $field Field data
* @param object $post Post object
* @return void
*/
public function display_meta_box_field ( $field = array(), $post ) {
if ( ! is_array( $field ) || 0 == count( $field ) ) return;
$field = '<p class="form-field"><label for="' . $field['id'] . '">' . $field['label'] . '</label>' . $this->display_field( $field, $post, false ) . '</p>' . "\n";
echo $field;
}
/**
* Save metabox fields
* @param integer $post_id Post ID
* @return void
*/
public function save_meta_boxes ( $post_id = 0 ) {
if ( ! $post_id ) return;
$post_type = get_post_type( $post_id );
$fields = apply_filters( $post_type . '_custom_fields', array(), $post_type );
if ( ! is_array( $fields ) || 0 == count( $fields ) ) return;
foreach ( $fields as $field ) {
if ( isset( $_REQUEST[ $field['id'] ] ) ) {
update_post_meta( $post_id, $field['id'], $this->validate_field( $_REQUEST[ $field['id'] ], $field['type'] ) );
} else {
update_post_meta( $post_id, $field['id'], '' );
}
}
}
}
\ No newline at end of file
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class autoshortcoder_Post_Type {
/**
* The name for the custom post type.
* @var string
* @access public
* @since 1.0.0
*/
public $post_type;
/**
* The plural name for the custom post type posts.
* @var string
* @access public
* @since 1.0.0
*/
public $plural;
/**
* The singular name for the custom post type posts.
* @var string
* @access public
* @since 1.0.0
*/
public $single;
/**
* The description of the custom post type.
* @var string
* @access public
* @since 1.0.0
*/
public $description;
/**
* The options of the custom post type.
* @var array
* @access public
* @since 1.0.0
*/
public $options;
public function __construct ( $post_type = '', $plural = '', $single = '', $description = '', $options = array() ) {
if ( ! $post_type || ! $plural || ! $single ) return;
// Post type name and labels
$this->post_type = $post_type;
$this->plural = $plural;
$this->single = $single;
$this->description = $description;
$this->options = $options;
// Regsiter post type
add_action( 'init' , array( $this, 'register_post_type' ) );
// Display custom update messages for posts edits
add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
add_filter( 'bulk_post_updated_messages', array( $this, 'bulk_updated_messages' ), 10, 2 );
}
/**
* Register new post type
* @return void
*/
public function register_post_type () {
$labels = array(
'name' => $this->plural,
'singular_name' => $this->single,
'name_admin_bar' => $this->single,
'add_new' => _x( 'Add New', $this->post_type , 'autoshortcoder' ),
'add_new_item' => sprintf( __( 'Add New %s' , 'autoshortcoder' ), $this->single ),
'edit_item' => sprintf( __( 'Edit %s' , 'autoshortcoder' ), $this->single ),
'new_item' => sprintf( __( 'New %s' , 'autoshortcoder' ), $this->single ),
'all_items' => sprintf( __( 'All %s' , 'autoshortcoder' ), $this->plural ),
'view_item' => sprintf( __( 'View %s' , 'autoshortcoder' ), $this->single ),
'search_items' => sprintf( __( 'Search %s' , 'autoshortcoder' ), $this->plural ),
'not_found' => sprintf( __( 'No %s Found' , 'autoshortcoder' ), $this->plural ),
'not_found_in_trash' => sprintf( __( 'No %s Found In Trash' , 'autoshortcoder' ), $this->plural ),
'parent_item_colon' => sprintf( __( 'Parent %s' ), $this->single ),
'menu_name' => $this->plural,
);
$args = array(
'labels' => apply_filters( $this->post_type . '_labels', $labels ),
'description' => $this->description,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'comments', 'thumbnail' ),
'menu_position' => 5,
'menu_icon' => 'dashicons-admin-post',
);
$args = array_merge($args, $this->options);
register_post_type( $this->post_type, apply_filters( $this->post_type . '_register_args', $args, $this->post_type ) );
}
/**
* Set up admin messages for post type
* @param array $messages Default message
* @return array Modified messages
*/
public function updated_messages ( $messages = array() ) {
global $post, $post_ID;
$messages[ $this->post_type ] = array(
0 => '',
1 => sprintf( __( '%1$s updated. %2$sView %3$s%4$s.' , 'autoshortcoder' ), $this->single, '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', $this->single, '</a>' ),
2 => __( 'Custom field updated.' , 'autoshortcoder' ),
3 => __( 'Custom field deleted.' , 'autoshortcoder' ),
4 => sprintf( __( '%1$s updated.' , 'autoshortcoder' ), $this->single ),
5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s.' , 'autoshortcoder' ), $this->single, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __( '%1$s published. %2$sView %3$s%4s.' , 'autoshortcoder' ), $this->single, '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', $this->single, '</a>' ),
7 => sprintf( __( '%1$s saved.' , 'autoshortcoder' ), $this->single ),
8 => sprintf( __( '%1$s submitted. %2$sPreview post%3$s%4$s.' , 'autoshortcoder' ), $this->single, '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', $this->single, '</a>' ),
9 => sprintf( __( '%1$s scheduled for: %2$s. %3$sPreview %4$s%5$s.' , 'autoshortcoder' ), $this->single, '<strong>' . date_i18n( __( 'M j, Y @ G:i' , 'autoshortcoder' ), strtotime( $post->post_date ) ) . '</strong>', '<a target="_blank" href="' . esc_url( get_permalink( $post_ID ) ) . '">', $this->single, '</a>' ),
10 => sprintf( __( '%1$s draft updated. %2$sPreview %3$s%4$s.' , 'autoshortcoder' ), $this->single, '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', $this->single, '</a>' ),
);
return $messages;
}
/**
* Set up bulk admin messages for post type
* @param array $bulk_messages Default bulk messages
* @param array $bulk_counts Counts of selected posts in each status
* @return array Modified messages
*/
public function bulk_updated_messages ( $bulk_messages = array(), $bulk_counts = array() ) {
$bulk_messages[ $this->post_type ] = array(
'updated' => sprintf( _n( '%1$s %2$s updated.', '%1$s %3$s updated.', $bulk_counts['updated'], 'autoshortcoder' ), $bulk_counts['updated'], $this->single, $this->plural ),
'locked' => sprintf( _n( '%1$s %2$s not updated, somebody is editing it.', '%1$s %3$s not updated, somebody is editing them.', $bulk_counts['locked'], 'autoshortcoder' ), $bulk_counts['locked'], $this->single, $this->plural ),
'deleted' => sprintf( _n( '%1$s %2$s permanently deleted.', '%1$s %3$s permanently deleted.', $bulk_counts['deleted'], 'autoshortcoder' ), $bulk_counts['deleted'], $this->single, $this->plural ),
'trashed' => sprintf( _n( '%1$s %2$s moved to the Trash.', '%1$s %3$s moved to the Trash.', $bulk_counts['trashed'], 'autoshortcoder' ), $bulk_counts['trashed'], $this->single, $this->plural ),
'untrashed' => sprintf( _n( '%1$s %2$s restored from the Trash.', '%1$s %3$s restored from the Trash.', $bulk_counts['untrashed'], 'autoshortcoder' ), $bulk_counts['untrashed'], $this->single, $this->plural ),
);
return $bulk_messages;
}
}
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class autoshortcoder_Taxonomy {
/**
* The name for the taxonomy.
* @var string
* @access public
* @since 1.0.0
*/
public $taxonomy;
/**
* The plural name for the taxonomy terms.
* @var string
* @access public
* @since 1.0.0
*/
public $plural;
/**
* The singular name for the taxonomy terms.
* @var string
* @access public
* @since 1.0.0
*/
public $single;
/**
* The array of post types to which this taxonomy applies.
* @var array
* @access public
* @since 1.0.0
*/
public $post_types;
/**
* The array of taxonomy arguments
* @var array
* @access public
* @since 1.0.0
*/
public $taxonomy_args;
public function __construct ( $taxonomy = '', $plural = '', $single = '', $post_types = array(), $tax_args = array() ) {
if ( ! $taxonomy || ! $plural || ! $single ) return;
// Post type name and labels
$this->taxonomy = $taxonomy;
$this->plural = $plural;
$this->single = $single;
if ( ! is_array( $post_types ) ) {
$post_types = array( $post_types );
}
$this->post_types = $post_types;
$this->taxonomy_args = $tax_args;
// Register taxonomy
add_action('init', array( $this, 'register_taxonomy' ) );
}
/**
* Register new taxonomy
* @return void
*/
public function register_taxonomy () {
$labels = array(
'name' => $this->plural,
'singular_name' => $this->single,
'menu_name' => $this->plural,
'all_items' => sprintf( __( 'All %s' , 'autoshortcoder' ), $this->plural ),
'edit_item' => sprintf( __( 'Edit %s' , 'autoshortcoder' ), $this->single ),
'view_item' => sprintf( __( 'View %s' , 'autoshortcoder' ), $this->single ),
'update_item' => sprintf( __( 'Update %s' , 'autoshortcoder' ), $this->single ),
'add_new_item' => sprintf( __( 'Add New %s' , 'autoshortcoder' ), $this->single ),
'new_item_name' => sprintf( __( 'New %s Name' , 'autoshortcoder' ), $this->single ),
'parent_item' => sprintf( __( 'Parent %s' , 'autoshortcoder' ), $this->single ),
'parent_item_colon' => sprintf( __( 'Parent %s:' , 'autoshortcoder' ), $this->single ),
'search_items' => sprintf( __( 'Search %s' , 'autoshortcoder' ), $this->plural ),
'popular_items' => sprintf( __( 'Popular %s' , 'autoshortcoder' ), $this->plural ),
'separate_items_with_commas' => sprintf( __( 'Separate %s with commas' , 'autoshortcoder' ), $this->plural ),
'add_or_remove_items' => sprintf( __( 'Add or remove %s' , 'autoshortcoder' ), $this->plural ),
'choose_from_most_used' => sprintf( __( 'Choose from the most used %s' , 'autoshortcoder' ), $this->plural ),
'not_found' => sprintf( __( 'No %s found' , 'autoshortcoder' ), $this->plural ),
);
$args = array(
'label' => $this->plural,
'labels' => apply_filters( $this->taxonomy . '_labels', $labels ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'meta_box_cb' => null,
'show_admin_column' => true,
'update_count_callback' => '',
'query_var' => $this->taxonomy,
'rewrite' => true,
'sort' => '',
);
$args = array_merge($args, $this->taxonomy_args);
register_taxonomy( $this->taxonomy, $this->post_types, apply_filters( $this->taxonomy . '_register_args', $args, $this->taxonomy, $this->post_types ) );
}
}
<?php
// Silence is golden
\ No newline at end of file
=== autoshortcoder ===
Contributors: nextime
Donate link: http://www.nexlab.net/supportus
Tags: wordpress, plugin, shortcodes
Requires at least: 3.9
Tested up to: 4.5.2
Stable tag: 1.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Programmatically add shortcodes to pages and posts based on tags
== Description ==
Programmatically add any shortcode to pages and posts based on tags after the content.
== Installation ==
Installing "autoshortcoder" can be done either by searching for "autoshortcoder" via the "Plugins > Add New" screen in your WordPress dashboard, or by using the following steps:
1. Download the plugin via WordPress.org
1. Upload the ZIP file through the 'Plugins > Add New > Upload' screen in your WordPress dashboard
1. Activate the plugin through the 'Plugins' menu in WordPress
== Changelog ==
= 1.0 =
* 2016-05-21
* Initial release
<?php
/**
*
* This file runs when the plugin in uninstalled (deleted).
* This will not run when the plugin is deactivated.
* Ideally you will add all your clean-up scripts here
* that will clean-up unused meta, options, etc. in the database.
*
*/
// If plugin is not being uninstalled, exit (do nothing)
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Do something here if plugin is being uninstalled.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment