mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-06-05 15:08:20 +09:00
Add optional shortcode buttons
This commit is contained in:
@@ -45,6 +45,7 @@ function display_featured_image_genesis_require() {
|
||||
'class-displayfeaturedimagegenesis-rss',
|
||||
'class-displayfeaturedimagegenesis-settings',
|
||||
'class-displayfeaturedimagegenesis-taxonomies',
|
||||
'sixtenpress-shortcodes/sixtenpress-shortcodes',
|
||||
);
|
||||
|
||||
foreach ( $files as $file ) {
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
/**
|
||||
* Class DisplayFeaturedImageGenesisDoSetting
|
||||
* @package Display_Featured_Image_Genesis
|
||||
* @package Display_Featured_Image_Genesis
|
||||
* @copyright 2016 Robin Cornett
|
||||
*/
|
||||
class DisplayFeaturedImageGenesisGetSetting {
|
||||
|
||||
/**
|
||||
* Define the default plugin settings.
|
||||
* @return mixed|void
|
||||
* @return array
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function defaults() {
|
||||
@@ -30,6 +30,11 @@ class DisplayFeaturedImageGenesisGetSetting {
|
||||
'centeredX' => 1,
|
||||
'centeredY' => 1,
|
||||
'fade' => 750,
|
||||
'shortcode' => array(
|
||||
'displayfeaturedimagegenesis_term' => 0,
|
||||
'displayfeaturedimagegenesis_author' => 0,
|
||||
'displayfeaturedimagegenesis_post_type' => 0,
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
@@ -42,6 +47,7 @@ class DisplayFeaturedImageGenesisGetSetting {
|
||||
public function get_display_setting() {
|
||||
$defaults = $this->defaults();
|
||||
$setting = get_option( 'displayfeaturedimagegenesis', $defaults );
|
||||
|
||||
return wp_parse_args( $setting, $defaults );
|
||||
|
||||
}
|
||||
|
||||
@@ -134,14 +134,12 @@ class Display_Featured_Image_Genesis_Helper extends DisplayFeaturedImageGenesisG
|
||||
* @param $args
|
||||
*/
|
||||
public function do_checkbox_array( $args ) {
|
||||
$post_types = $this->get_content_types_built_in();
|
||||
foreach ( $post_types as $post_type ) {
|
||||
$object = get_post_type_object( $post_type );
|
||||
foreach ( $args['options'] as $key => $value ) {
|
||||
$type_args = array(
|
||||
'setting' => "{$args['setting']}][{$post_type}",
|
||||
'label' => $object->label,
|
||||
'setting' => "{$args['setting']}][{$key}",
|
||||
'label' => $value,
|
||||
'setting_name' => $args['setting'],
|
||||
'name' => $post_type,
|
||||
'name' => $key,
|
||||
);
|
||||
$this->do_checkbox( $type_args );
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
|
||||
/**
|
||||
* The plugin setting.
|
||||
* @var $setting string
|
||||
* @var $setting array
|
||||
*/
|
||||
protected $setting;
|
||||
|
||||
@@ -107,6 +107,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
$previous_user = get_option( 'displayfeaturedimagegenesis', false );
|
||||
if ( ! $previous_user ) {
|
||||
update_option( 'displayfeaturedimagegenesis_updatedterms', true );
|
||||
|
||||
return;
|
||||
}
|
||||
$this->term_option_query = $this->check_term_images();
|
||||
@@ -140,12 +141,14 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
|
||||
/**
|
||||
* Settings for options screen
|
||||
* @return array settings for backstretch image options
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public function register_settings() {
|
||||
register_setting( 'displayfeaturedimagegenesis', 'displayfeaturedimagegenesis', array( $this, 'do_validation_things' ) );
|
||||
register_setting( 'displayfeaturedimagegenesis', 'displayfeaturedimagegenesis', array(
|
||||
$this,
|
||||
'do_validation_things',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,9 +158,18 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
*/
|
||||
protected function define_tabs() {
|
||||
return array(
|
||||
'main' => array( 'id' => 'main', 'tab' => __( 'Main', 'display-featured-image-genesis' ) ),
|
||||
'style' => array( 'id' => 'style', 'tab' => __( 'Backstretch Output', 'display-featured-image-genesis' ) ),
|
||||
'cpt' => array( 'id' => 'cpt', 'tab' => __( 'Content Types', 'display-featured-image-genesis' ) ),
|
||||
'main' => array(
|
||||
'id' => 'main',
|
||||
'tab' => __( 'Main', 'display-featured-image-genesis' ),
|
||||
),
|
||||
'style' => array(
|
||||
'id' => 'style',
|
||||
'tab' => __( 'Backstretch Output', 'display-featured-image-genesis' ),
|
||||
),
|
||||
'cpt' => array(
|
||||
'id' => 'cpt',
|
||||
'tab' => __( 'Content Types', 'display-featured-image-genesis' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -168,7 +180,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
*/
|
||||
protected function register_sections() {
|
||||
return array(
|
||||
'main' => array(
|
||||
'main' => array(
|
||||
'id' => 'main',
|
||||
'title' => __( 'Optional Sitewide Settings', 'display-featured-image-genesis' ),
|
||||
),
|
||||
@@ -176,7 +188,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
'id' => 'style',
|
||||
'title' => __( 'Display Settings', 'display-featured-image-genesis' ),
|
||||
),
|
||||
'cpt' => array(
|
||||
'cpt' => array(
|
||||
'id' => 'cpt',
|
||||
'title' => __( 'Featured Images for Custom Content Types', 'display-featured-image-genesis' ),
|
||||
),
|
||||
@@ -211,49 +223,84 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
'title' => __( 'Always Use Default', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_checkbox',
|
||||
'section' => 'main',
|
||||
'args' => array( 'setting' => 'always_default', 'label' => __( 'Always use the default image, even if a featured image is set.', 'display-featured-image-genesis' ) ),
|
||||
'args' => array(
|
||||
'setting' => 'always_default',
|
||||
'label' => __( 'Always use the default image, even if a featured image is set.', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'exclude_front',
|
||||
'title' => __( 'Skip Front Page', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_checkbox',
|
||||
'section' => 'main',
|
||||
'args' => array( 'setting' => 'exclude_front', 'label' => __( 'Do not show the Featured Image on the Front Page of the site.', 'display-featured-image-genesis' ) ),
|
||||
'args' => array(
|
||||
'setting' => 'exclude_front',
|
||||
'label' => __( 'Do not show the Featured Image on the Front Page of the site.', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'keep_titles',
|
||||
'title' => __( 'Do Not Move Titles', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_checkbox',
|
||||
'section' => 'main',
|
||||
'args' => array( 'setting' => 'keep_titles', 'label' => __( 'Do not move the titles to overlay the backstretch Featured Image.', 'display-featured-image-genesis' ) ),
|
||||
'args' => array(
|
||||
'setting' => 'keep_titles',
|
||||
'label' => __( 'Do not move the titles to overlay the backstretch Featured Image.', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'move_excerpts',
|
||||
'title' => __( 'Move Excerpts/Archive Descriptions', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_checkbox',
|
||||
'section' => 'main',
|
||||
'args' => array( 'setting' => 'move_excerpts', 'label' => __( 'Move excerpts (if used) on single pages and move archive/taxonomy descriptions to overlay the Featured Image.', 'display-featured-image-genesis' ) ),
|
||||
'args' => array(
|
||||
'setting' => 'move_excerpts',
|
||||
'label' => __( 'Move excerpts (if used) on single pages and move archive/taxonomy descriptions to overlay the Featured Image.', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'is_paged',
|
||||
'title' => __( 'Show Featured Image on Subsequent Blog Pages', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_checkbox',
|
||||
'section' => 'main',
|
||||
'args' => array( 'setting' => 'is_paged', 'label' => __( 'Show featured image on pages 2+ of blogs and archives.', 'display-featured-image-genesis' ) ),
|
||||
'args' => array(
|
||||
'setting' => 'is_paged',
|
||||
'label' => __( 'Show featured image on pages 2+ of blogs and archives.', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'feed_image',
|
||||
'title' => __( 'Add Featured Image to Feed?', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_checkbox',
|
||||
'section' => 'main',
|
||||
'args' => array( 'setting' => 'feed_image', 'label' => __( 'Optionally, add the featured image to your RSS feed.', 'display-featured-image-genesis' ) ),
|
||||
'args' => array(
|
||||
'setting' => 'feed_image',
|
||||
'label' => __( 'Optionally, add the featured image to your RSS feed.', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'thumbnails',
|
||||
'title' => __( 'Archive Thumbnails', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_checkbox',
|
||||
'section' => 'main',
|
||||
'args' => array( 'setting' => 'thumbnails', 'label' => __( 'Use term/post type fallback images for content archives?', 'display-featured-image-genesis' ) ),
|
||||
'args' => array(
|
||||
'setting' => 'thumbnails',
|
||||
'label' => __( 'Use term/post type fallback images for content archives?', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'shortcode',
|
||||
'title' => __( 'Add Shortcode Buttons', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_checkbox_array',
|
||||
'section' => 'main',
|
||||
'args' => array(
|
||||
'setting' => 'shortcode',
|
||||
'options' => array(
|
||||
'displayfeaturedimagegenesis_term' => __( 'Featured Term Widget', 'display-featured-image-genesis' ),
|
||||
'displayfeaturedimagegenesis_author' => __( 'Featured Author Widget', 'display-featured-image-genesis' ),
|
||||
'displayfeaturedimagegenesis_post_type' => __( 'Featured Post Type Widget', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -266,21 +313,31 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
return array(
|
||||
array(
|
||||
'id' => 'less_header',
|
||||
'title' => __( 'Height' , 'display-featured-image-genesis' ),
|
||||
'title' => __( 'Height', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_number',
|
||||
'section' => 'style',
|
||||
'args' => array( 'setting' => 'less_header', 'label' => __( 'pixels to remove', 'display-featured-image-genesis' ), 'min' => 0, 'max' => 400 ),
|
||||
'args' => array(
|
||||
'setting' => 'less_header',
|
||||
'label' => __( 'pixels to remove', 'display-featured-image-genesis' ),
|
||||
'min' => 0,
|
||||
'max' => 400,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'max_height',
|
||||
'title' => __( 'Maximum Height' , 'display-featured-image-genesis' ),
|
||||
'title' => __( 'Maximum Height', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_number',
|
||||
'section' => 'style',
|
||||
'args' => array( 'setting' => 'max_height', 'label' => __( 'pixels', 'display-featured-image-genesis' ), 'min' => 100, 'max' => 1000 ),
|
||||
'args' => array(
|
||||
'setting' => 'max_height',
|
||||
'label' => __( 'pixels', 'display-featured-image-genesis' ),
|
||||
'min' => 100,
|
||||
'max' => 1000,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 'centeredX',
|
||||
'title' => __( 'Center Horizontally' , 'display-featured-image-genesis' ),
|
||||
'title' => __( 'Center Horizontally', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_radio_buttons',
|
||||
'section' => 'style',
|
||||
'args' => array(
|
||||
@@ -291,7 +348,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
),
|
||||
array(
|
||||
'id' => 'centeredY',
|
||||
'title' => __( 'Center Vertically' , 'display-featured-image-genesis' ),
|
||||
'title' => __( 'Center Vertically', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_radio_buttons',
|
||||
'section' => 'style',
|
||||
'args' => array(
|
||||
@@ -302,10 +359,15 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
),
|
||||
array(
|
||||
'id' => 'fade',
|
||||
'title' => __( 'Fade' , 'display-featured-image-genesis' ),
|
||||
'title' => __( 'Fade', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_number',
|
||||
'section' => 'style',
|
||||
'args' => array( 'setting' => 'fade', 'label' => __( 'milliseconds', 'display-featured-image-genesis' ), 'min' => 0, 'max' => 20000 ),
|
||||
'args' => array(
|
||||
'setting' => 'fade',
|
||||
'label' => __( 'milliseconds', 'display-featured-image-genesis' ),
|
||||
'min' => 0,
|
||||
'max' => 20000,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -335,14 +397,17 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
'title' => __( 'Skip Content Types', 'display-featured-image-genesis' ),
|
||||
'callback' => 'do_checkbox_array',
|
||||
'section' => 'cpt',
|
||||
'args' => array( 'setting' => 'skip' ),
|
||||
'args' => array(
|
||||
'setting' => 'skip',
|
||||
'options' => $this->get_post_types(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if ( $this->post_types ) {
|
||||
|
||||
foreach ( $this->post_types as $post ) {
|
||||
$object = get_post_type_object( $post );
|
||||
$object = get_post_type_object( $post );
|
||||
$fields[] = array(
|
||||
'id' => 'post_types][' . esc_attr( $object->name ),
|
||||
'title' => esc_attr( $object->label ),
|
||||
@@ -352,6 +417,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -432,6 +498,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
*/
|
||||
protected function default_image_description() {
|
||||
$large = $this->common->minimum_backstretch_width();
|
||||
|
||||
return sprintf(
|
||||
esc_html__( 'If you would like to use a default image for the featured image, upload it here. Must be at least %1$s pixels wide.', 'display-featured-image-genesis' ),
|
||||
absint( $large + 1 )
|
||||
@@ -489,9 +556,26 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the post types as options.
|
||||
* @return array
|
||||
*/
|
||||
protected function get_post_types() {
|
||||
$post_types = $this->get_content_types_built_in();
|
||||
$options = array();
|
||||
foreach ( $post_types as $post_type ) {
|
||||
$object = get_post_type_object( $post_type );
|
||||
$options[ $post_type ] = $object->label;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* validate all inputs
|
||||
*
|
||||
* @param string $new_value various settings
|
||||
*
|
||||
* @return string number or URL
|
||||
*
|
||||
* @since 1.4.0
|
||||
@@ -519,6 +603,10 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
$new_value[ $field['id'] ] = $this->check_value( $new_value[ $field['id'] ], $this->setting[ $field['id'] ], $field['args']['min'], $field['args']['max'] );
|
||||
} elseif ( 'do_radio_buttons' === $field['callback'] ) {
|
||||
$new_value[ $field['id'] ] = absint( $new_value[ $field['id'] ] );
|
||||
} elseif ( 'do_checkbox_array' === $field['callback'] ) {
|
||||
foreach ( $field['args']['options'] as $option ) {
|
||||
$new_value[ $field['id'] ][ $option ] = $this->one_zero( $new_value[ $field['id'] ][ $option ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,11 +657,13 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the numeric value against the allowed range. If it's within the range, return it; otherwise, return the old value.
|
||||
* Check the numeric value against the allowed range. If it's within the range, return it; otherwise, return the
|
||||
* old value.
|
||||
*
|
||||
* @param $new_value int new submitted value
|
||||
* @param $old_value int old setting value
|
||||
* @param $min int minimum value
|
||||
* @param $max int maximum value
|
||||
* @param $min int minimum value
|
||||
* @param $max int maximum value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -581,6 +671,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
if ( $new_value >= $min && $new_value <= $max ) {
|
||||
return (int) $new_value;
|
||||
}
|
||||
|
||||
return (int) $old_value;
|
||||
}
|
||||
|
||||
@@ -601,21 +692,22 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
$rows = $this->term_option_query;
|
||||
if ( ! $rows ) {
|
||||
update_option( 'displayfeaturedimagegenesis_updatedterms', true );
|
||||
|
||||
return;
|
||||
}
|
||||
$message = sprintf( '<p>%s</p>', __( 'WordPress 4.4 introduces term metadata for categories, tags, and other taxonomies. This is your opportunity to optionally update all impacted terms on your site to use the new metadata.', 'display-featured-image-genesis' ) );
|
||||
$message = sprintf( '<p>%s</p>', __( 'WordPress 4.4 introduces term metadata for categories, tags, and other taxonomies. This is your opportunity to optionally update all impacted terms on your site to use the new metadata.', 'display-featured-image-genesis' ) );
|
||||
$message .= sprintf( '<p>%s</p>', __( 'This <strong>will modify</strong> your database (potentially many entries at once), so if you\'d rather do it yourself, you can. Here\'s a list of the affected terms:', 'display-featured-image-genesis' ) );
|
||||
$message .= '<ul style="margin-left:24px;list-style-type:disc;">';
|
||||
foreach ( $rows as $row ) {
|
||||
$term_id = str_replace( 'displayfeaturedimagegenesis_', '', $row );
|
||||
$term = get_term( (int) $term_id );
|
||||
$term_id = str_replace( 'displayfeaturedimagegenesis_', '', $row );
|
||||
$term = get_term( (int) $term_id );
|
||||
if ( ! is_wp_error( $term ) && ! is_null( $term ) ) {
|
||||
$message .= edit_term_link( $term->name, '<li>', '</li>', $term, false );
|
||||
}
|
||||
}
|
||||
$message .= '</ul>';
|
||||
$message .= sprintf( '<p>%s</p>', __( 'To get rid of this notice, you can 1) update your terms by hand; 2) click the update button (please check your terms afterward); or 3) click the dismiss button.', 'display-featured-image-genesis' ) );
|
||||
$faq = sprintf( __( 'For more information, please visit the plugin\'s <a href="%s" target="_blank">Frequently Asked Questions</a> on WordPress.org.', 'display-featured-image-genesis' ), esc_url( 'https://wordpress.org/plugins/display-featured-image-genesis/faq/' ) );
|
||||
$faq = sprintf( __( 'For more information, please visit the plugin\'s <a href="%s" target="_blank">Frequently Asked Questions</a> on WordPress.org.', 'display-featured-image-genesis' ), esc_url( 'https://wordpress.org/plugins/display-featured-image-genesis/faq/' ) );
|
||||
$message .= sprintf( '<p>%s</p>', $faq );
|
||||
echo '<div class="updated">' . wp_kses_post( $message );
|
||||
echo '<form action="" method="post">';
|
||||
@@ -679,9 +771,11 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
|
||||
/**
|
||||
* Get IDs of terms with featured images
|
||||
* @param array $term_ids empty array
|
||||
*
|
||||
* @param array $term_ids empty array
|
||||
*
|
||||
* @return array all terms with featured images
|
||||
* @since 2.4.0
|
||||
* @since 2.4.0
|
||||
* @deprecated 2.6.1 by check_term_images() due to heavy load on sites with many terms
|
||||
*/
|
||||
protected function get_affected_terms( $affected_terms = array() ) {
|
||||
@@ -707,6 +801,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $affected_terms;
|
||||
}
|
||||
|
||||
@@ -718,6 +813,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
*/
|
||||
protected function terms_have_been_updated() {
|
||||
$updated = get_option( 'displayfeaturedimagegenesis_updatedterms', false );
|
||||
|
||||
return (bool) $updated;
|
||||
}
|
||||
|
||||
|
||||
@@ -337,6 +337,9 @@ class Display_Featured_Image_Genesis {
|
||||
foreach ( array( 'author', 'post_type', 'term' ) as $shortcode ) {
|
||||
add_shortcode( "displayfeaturedimagegenesis_{$shortcode}", array( $shortcode_class, "shortcode_{$shortcode}" ) );
|
||||
}
|
||||
add_filter( 'sixtenpress_shortcode_inline_css', array( $shortcode_class, 'inline_css' ) );
|
||||
add_action( 'sixtenpress_shortcode_init', array( $shortcode_class, 'shortcode_buttons' ) );
|
||||
add_action( 'sixtenpress_shortcode_modal', array( $shortcode_class, 'do_modal' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
# Six/Ten Press Shortcodes
|
||||
|
||||
This project is meant to be dropped into an existing WordPress plugin or theme and used to allow developers to easily create a button for their shortcode. With fields added to the new shortcode modal, the shortcode will be parsed and inserted into the WordPress editor.
|
||||
|
||||
## Installation
|
||||
|
||||
To use this, add the entire folder to your plugin/theme project. Include the main file with something like this:
|
||||
|
||||
```php
|
||||
include plugin_dir_path( __FILE__ ) . 'sixtenpress-shortcodes/sixtenpress-shortcodes.php';
|
||||
```
|
||||
|
||||
## Frequently Asked Questions
|
||||
|
||||
### How do I get started?
|
||||
|
||||
To add a new shortcode button to your editor, you'll need at least two functions: one to register your custom button and one to populate the modal.
|
||||
|
||||
To register your custom button, use this code. Some of the parameters are optional, but more information is better than less.
|
||||
|
||||
```php
|
||||
add_action( 'sixtenpress_shortcode_init', 'prefix_register_shortcode_button' );
|
||||
/**
|
||||
* Register the grid shortcode button.
|
||||
*/
|
||||
function prefix_register_shortcode_button() {
|
||||
sixtenpress_shortcode_register(
|
||||
'prefix_my_shortcode', // your actual shortcode
|
||||
array(
|
||||
'modal' => 'prefix_custom_shortcode', // this will be used to create a custom ID and class for your modal
|
||||
'button' => array(
|
||||
'id' => 'prefix-button', // the unique ID for your custom button
|
||||
'class' => 'prefix-build-shortcode', // unique class, which you may want to include for styling
|
||||
'dashicon' => 'dashicons-grid-view', // optional, if you want to use a Dashicon
|
||||
'label' => __( 'Add My Shortcode', 'prefix-textdomain' ), // Custom label for your button
|
||||
),
|
||||
'self' => true, // set to false if your shortcode is not self-closing
|
||||
'labels' => array(
|
||||
'title' => __( 'Create Shortcode', 'prefix-textdomain' ), // optionally customize the title of the modal window
|
||||
'insert' => __( 'Insert Shortcode', 'prefix-textdomain' ), // optionally change the text for the modal insert button
|
||||
),
|
||||
'group_fields' => array( 'show' ), // optional: use this if you have multi-check fields (groups of checkboxes)
|
||||
) );
|
||||
}
|
||||
```
|
||||
|
||||
Fill your new modal with a great form. There are several ways to approach this--basically, any way you can create a form, do it. Here's an example using CMB2 fields:
|
||||
|
||||
```php
|
||||
add_action( 'sixtenpress_shortcode_modal_prefix_my_shortcode', 'prefix_shortcode_modal' );
|
||||
/**
|
||||
* Add the form to the modal.
|
||||
*
|
||||
* @param $shortcode
|
||||
*/
|
||||
function prefix_shortcode_modal( $shortcode ) {
|
||||
$object = cmb2_get_metabox( prefix_custom_shortcode_config(), 'prefix_custom_shortcode' );
|
||||
$form = '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s</form>';
|
||||
cmb2_metabox_form( $object, 'prefix-build-shortcode', array(
|
||||
'form_format' => $form,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the fields for the modal CMB2 form.
|
||||
* @return array
|
||||
*/
|
||||
function prefix_custom_shortcode_config() {
|
||||
return array(
|
||||
'id' => 'prefix_custom_shortcode', // Required for CMB2
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => __( 'Test Text Small', 'prefix-textdomain' ),
|
||||
'desc' => __( 'field description (optional)', 'prefix-textdomain' ),
|
||||
'default' => __( 'default shortcode param value', 'prefix-textdomain' ),
|
||||
'id' => 'shortcode_param',
|
||||
'type' => 'text_small',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Depending on how your form is built, you may need to also enqueue additional scripts and/or styles.
|
||||
|
||||
With this example, your shortcode will be output like this:
|
||||
|
||||
[prefix_custom_shortcode shortcode_param="text value"]
|
||||
|
||||
### Current Notes and Limitations
|
||||
|
||||
If your shortcode form that defaults to `true` and should be included as `false` if it is unchecked, make the checkbox a required field. Otherwise, the attribute is assumed to be optional and will be omitted from the final shortcode.
|
||||
|
||||
Currently, CMB2 image fields do not play well in the modal form. The preview fails due to a JavaScript error, and since the form creates both an image and an image_id input, both are passed as attributes, when presumably only the ID is desired.
|
||||
|
||||
CMB2 WYSIWYG fields fail completely, with no errors. If content is needed using CMB2, a textarea is currently a better choice.
|
||||
|
||||
If an image ID is required, Six/Ten Press image fields in a group will work, as in the Leaven Proofing plugin. Images in groups are saved as ID only.
|
||||
|
||||
## Credits
|
||||
* built by [Robin Cornett](https://robincornett.com)
|
||||
|
||||
### Changelog
|
||||
|
||||
#### 0.3.2
|
||||
* reduced unnecessary CSS
|
||||
* tweaked filter for hooks on which to load the modal buttons
|
||||
|
||||
#### 0.3.1
|
||||
* added: filter to restrict media buttons to certain editors
|
||||
|
||||
#### 0.3.0
|
||||
* added: reset inputs to default/original parameters
|
||||
|
||||
#### 0.2.0
|
||||
* change modal show/hide (enables easier implementation of tinyMCE)
|
||||
* allow required fields (originally, unchecked checkboxes were not passed to output string)
|
||||
* improve checkbox validation
|
||||
|
||||
#### 0.1.1
|
||||
* fix inline style running multiple times
|
||||
|
||||
#### 0.1.0
|
||||
* initial release
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
* Add a hook to initialize our code.
|
||||
*/
|
||||
add_action( 'admin_init', function () {
|
||||
if ( ! did_action( 'sixtenpress_shortcode_init' ) ) {
|
||||
do_action( 'sixtenpress_shortcode_init' );
|
||||
}
|
||||
} );
|
||||
|
||||
/**
|
||||
* Call this function hooked into `sixtenpress_shortcode_init` for proper
|
||||
* timing and no failure.
|
||||
*
|
||||
* @param $shortcode
|
||||
* @param $args
|
||||
*/
|
||||
function sixtenpress_shortcode_register( $shortcode, $args ) {
|
||||
new SixTenPressShortcodes( $shortcode, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Class SixTenPressShortcodes
|
||||
*/
|
||||
class SixTenPressShortcodes {
|
||||
|
||||
/**
|
||||
* Flag to determine if media modal is loaded.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $loaded = false;
|
||||
|
||||
/**
|
||||
* The shortcode to register.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $shortcode;
|
||||
|
||||
/**
|
||||
* The custom args for the shortcode.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $shortcode_args;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix = 'sixtenpress';
|
||||
|
||||
/**
|
||||
* SixTenPressShortcodes constructor.
|
||||
*
|
||||
* @param $shortcode
|
||||
* @param $shortcode_args
|
||||
*/
|
||||
public function __construct( $shortcode, $shortcode_args ) {
|
||||
$this->shortcode = $shortcode;
|
||||
$this->shortcode_args = $this->merge( $shortcode_args, $this->defaults() );
|
||||
if ( ! $this->shortcode_args ) {
|
||||
return;
|
||||
}
|
||||
foreach ( $this->hooks() as $hook ) {
|
||||
add_action( $hook, array( $this, 'start_editor' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select which hooks to call the shortcode buttons on.
|
||||
* load-{post}.php is the earliest.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function hooks() {
|
||||
return apply_filters( 'sixtenpress_shortcode_hooks', array( 'load-post.php', 'load-post-new.php' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge any custom args with the defaults.
|
||||
*
|
||||
* @param $custom_args
|
||||
* @param $defaults
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function merge( $custom_args, $defaults ) {
|
||||
foreach ( array( 'button', 'labels' ) as $key ) {
|
||||
if ( array_key_exists( $key, $custom_args ) ) {
|
||||
$custom_args[ $key ] = wp_parse_args( $custom_args[ $key ], $defaults[ $key ] );
|
||||
}
|
||||
}
|
||||
$custom_args['slug'] = ! isset( $custom_args['slug'] ) && isset( $custom_args['modal'] ) ? $custom_args['modal'] : $custom_args['slug'];
|
||||
|
||||
return wp_parse_args( $custom_args, $defaults );
|
||||
}
|
||||
|
||||
/**
|
||||
* Default shortcode args.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function defaults() {
|
||||
return array(
|
||||
'modal' => false,
|
||||
'button' => array(
|
||||
'id' => $this->prefix,
|
||||
'class' => $this->prefix,
|
||||
'dashicon' => false,
|
||||
'label' => __( 'Add Element', 'sixtenpress-shortcodes' ),
|
||||
),
|
||||
'self' => true,
|
||||
'labels' => array(
|
||||
'title' => __( 'Create', 'sixtenpress-shortcodes' ),
|
||||
'close' => __( 'Close', 'sixtenpress-shortcodes' ),
|
||||
'cancel' => __( 'Cancel', 'sixtenpress-shortcodes' ),
|
||||
'insert' => __( 'Insert', 'sixtenpress-shortcodes' ),
|
||||
),
|
||||
'slug' => $this->prefix,
|
||||
'group' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all needful functions for the editor.
|
||||
*/
|
||||
public function start_editor() {
|
||||
add_filter( 'sixtenpress_shortcode_localization', array( $this, 'localization_args' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
|
||||
add_action( 'media_buttons', array( $this, 'media_buttons' ), 98 );
|
||||
add_action( 'admin_footer', array( $this, 'widget_builder_modal' ) );
|
||||
add_filter( 'sixtenpress_admin_color_picker', '__return_true' );
|
||||
add_action( 'admin_print_scripts', array( $this, 'localize' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom button beside the media uploader button.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $id The TinyMCE Editor ID
|
||||
*/
|
||||
public function media_buttons( $id ) {
|
||||
// Allow devs to override/cancel media button output.
|
||||
$show = apply_filters( 'sixtenpress_shortcode_media_button', true, $this->shortcode, $id );
|
||||
if ( ! $show ) {
|
||||
return;
|
||||
}
|
||||
printf( '<button type="button" id="%1$s" class="button %2$s" title="%4$s" data-editor="%5$s">%3$s%4$s</button>',
|
||||
esc_attr( $this->shortcode_args['button']['id'] ),
|
||||
esc_attr( $this->shortcode_args['button']['class'] ),
|
||||
$this->shortcode_args['button']['dashicon'] ? sprintf( '<span class="wp-media-buttons-icon dashicons %s"></span> ', esc_attr( $this->shortcode_args['button']['dashicon'] ) ) : '',
|
||||
esc_html( $this->shortcode_args['button']['label'] ),
|
||||
esc_attr( $id )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue the scripts and styles needed for the modal.
|
||||
*/
|
||||
public function enqueue() {
|
||||
$minify = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
wp_enqueue_script( 'sixtenpress-editor-script', plugin_dir_url( __FILE__ ) . "js/shortcode-editor{$minify}.js", array( 'jquery' ), SIXTENPRESSSHORTCODES_VERSION, true );
|
||||
|
||||
add_filter( 'sixtenpress_admin_style', '__return_true' );
|
||||
wp_enqueue_style( 'sixtenpress-editor', plugin_dir_url( __FILE__ ) . 'css/sixtenpress-editor.css', array(), SIXTENPRESSSHORTCODES_VERSION, 'screen' );
|
||||
|
||||
$css = apply_filters( 'sixtenpress_shortcode_inline_css', '' );
|
||||
if ( $css ) {
|
||||
wp_add_inline_style( 'sixtenpress-editor', $this->minify_css( $css ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Minify inline CSS a bit before outputting as inline style.
|
||||
*
|
||||
* @param $css
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function minify_css( $css ) {
|
||||
$css = str_replace( "\t", '', $css );
|
||||
$css = str_replace( array( "\n", "\r" ), ' ', $css );
|
||||
|
||||
return sanitize_text_field( strip_tags( $css ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data for the script.
|
||||
*/
|
||||
public function localize() {
|
||||
wp_localize_script( 'sixtenpress-editor-script', 'SixTenShortcodes', apply_filters( 'sixtenpress_shortcode_localization', array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the array of args for our script.
|
||||
*
|
||||
* @param $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function localization_args( $args ) {
|
||||
$new[ $this->shortcode ] = array(
|
||||
'modal' => $this->shortcode_args['modal'],
|
||||
'button' => $this->shortcode_args['button']['class'],
|
||||
'shortcode' => $this->shortcode,
|
||||
'self' => $this->shortcode_args['self'],
|
||||
'slug' => $this->shortcode_args['slug'],
|
||||
'group' => (array) $this->shortcode_args['group'],
|
||||
);
|
||||
|
||||
return array_merge( $args, $new );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the widget builder modal to insert a widget into an editor.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public function widget_builder_modal() {
|
||||
|
||||
if ( $this->loaded ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->loaded = true;
|
||||
include( plugin_dir_path( __FILE__ ) . 'modal.php' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
.sixtenpress-default-ui{-webkit-box-sizing:border-box;box-sizing:border-box}.sixtenpress-default-ui input,.sixtenpress-default-ui select,.sixtenpress-default-ui img{max-width:100%!important}.sixtenpress-default-ui .media-modal-content{margin:0 auto;max-width:800px}.sixtenpress-default-ui .media-frame-content{padding:24px}.sixtenpress-default-ui .media-frame-toolbar{left:0}
|
||||
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Robin Cornett
|
||||
*/
|
||||
|
||||
;(function ( document, $, undefined ) {
|
||||
'use strict';
|
||||
|
||||
var SixTenShortcodesEditor = {};
|
||||
|
||||
/**
|
||||
* Initialize. Cycle through the parameters for each shortcode button.
|
||||
*/
|
||||
SixTenShortcodesEditor.init = function () {
|
||||
|
||||
Object.keys( SixTenShortcodesEditor.params ).forEach( function ( key ) {
|
||||
if ( SixTenShortcodesEditor.params.hasOwnProperty( key ) ) {
|
||||
var IndividualObject = SixTenShortcodesEditor.params[key],
|
||||
sixtenpress_trigger_target = false,
|
||||
sixtenpress_editor_frame = false,
|
||||
modal = '.' + IndividualObject.modal,
|
||||
inputs = $( '#' + IndividualObject.modal ).find( ":input" ),
|
||||
defaults = _defaults( inputs );
|
||||
|
||||
$( '.' + IndividualObject.button ).click( _open );
|
||||
$( '.sixtenpress-default-ui .sixtenpress-insert' ).click( _insert );
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the modal.
|
||||
*/
|
||||
function _open( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
// Store the trigger target.
|
||||
sixtenpress_trigger_target = e.target;
|
||||
sixtenpress_editor_frame = true;
|
||||
$( modal ).show();
|
||||
|
||||
$( '.media-modal-close, .media-modal-backdrop, .sixtenpress-cancel-insertion' ).click( _hide );
|
||||
$( document ).on( 'keydown', function ( e ) {
|
||||
if ( 27 === e.keyCode && sixtenpress_editor_frame ) {
|
||||
_hide( e );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the parsed shortcode into the editor and hide the modal.
|
||||
*/
|
||||
function _insert( e ) {
|
||||
e.preventDefault();
|
||||
if ( $( sixtenpress_trigger_target ).hasClass( IndividualObject.button ) ) {
|
||||
var string = _getAttributes( inputs, IndividualObject.group ),
|
||||
multi = IndividualObject.group ? _getMulti( IndividualObject.group, IndividualObject.slug ) : '',
|
||||
output = '';
|
||||
if ( string ) {
|
||||
output = '[' + IndividualObject.shortcode + multi + string + ']';
|
||||
if ( ! IndividualObject.self ) {
|
||||
output += _getContent( IndividualObject.slug, IndividualObject.modal ) + '[/' + IndividualObject.shortcode + ']';
|
||||
}
|
||||
tinymce.get( $( sixtenpress_trigger_target ).attr( 'data-editor' ) ).execCommand( 'mceInsertContent', false, output );
|
||||
}
|
||||
}
|
||||
|
||||
_hide( e );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the modal.
|
||||
* @param e
|
||||
* @private
|
||||
*/
|
||||
function _hide( e ) {
|
||||
e.preventDefault();
|
||||
$( modal ).hide();
|
||||
_reset();
|
||||
sixtenpress_trigger_target = sixtenpress_editor_frame = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to reset all inputs to their default state.
|
||||
* @private
|
||||
*/
|
||||
function _reset() {
|
||||
$( inputs ).each( function ( index ) {
|
||||
var id = $( this ).attr( 'id' ),
|
||||
type = this.type;
|
||||
if ( 'checkbox' === type ) {
|
||||
var checked = ( 'checked' === defaults[id] );
|
||||
$( this ).attr( 'checked', checked );
|
||||
} else {
|
||||
$( this ).val( defaults[id] );
|
||||
}
|
||||
} );
|
||||
|
||||
$( modal + ' .upload-file-preview' ).remove();
|
||||
|
||||
_colorPickers();
|
||||
_tinymceClear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear and reset color pickers.
|
||||
* @private
|
||||
*/
|
||||
function _colorPickers() {
|
||||
var $colorPicker = $( modal ).find( '.wp-picker-container' );
|
||||
|
||||
if ( $colorPicker.length ) {
|
||||
$colorPicker.each( function () {
|
||||
var $pickerParent = $( this ).parent();
|
||||
$pickerParent.html( $pickerParent.find( 'input[type="text"].color-field' ).attr( 'style', '' ) );
|
||||
$pickerParent.find( 'input[type="text"].wp-color-picker' ).each( function () {
|
||||
var $this = $( this ),
|
||||
settings = $this.data( 'colorpicker' ) || {};
|
||||
$this.wpColorPicker( $.extend( {}, false, settings ) );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear any tinymce editors.
|
||||
* @private
|
||||
*/
|
||||
function _tinymceClear() {
|
||||
var $id = $( modal ).find( "textarea[id*='" + IndividualObject.slug + "']" );
|
||||
|
||||
if ( $id.length ) {
|
||||
var editor = $id.attr( 'id' );
|
||||
tinymce.get( editor ).setContent( '' );
|
||||
}
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the default values for each input.
|
||||
*
|
||||
* @param inputs
|
||||
* @returns {Array}
|
||||
* @private
|
||||
*/
|
||||
function _defaults( inputs ) {
|
||||
var defaults = [];
|
||||
$( inputs ).each( function ( index ) {
|
||||
var id = $( this ).attr( 'id' );
|
||||
if ( undefined !== id ) {
|
||||
defaults[id] = $( this ).val();
|
||||
}
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
defaults[id] = 'checked';
|
||||
}
|
||||
} );
|
||||
return defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shortcode attributes as a string.
|
||||
*
|
||||
* @param inputs
|
||||
* @param group
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
function _getAttributes( inputs, group ) {
|
||||
var output = '';
|
||||
$( inputs ).each( function ( index ) {
|
||||
var original_id = $( this ).attr( 'id' ),
|
||||
value = $( this ).val(),
|
||||
type = this.type;
|
||||
if ( original_id ) {
|
||||
var id = original_id.substr( original_id.lastIndexOf( '-' ) + 1 );
|
||||
if ( id.includes( 'nonce' ) ) {
|
||||
value = '';
|
||||
}
|
||||
if ( 'checkbox' === type ) {
|
||||
if ( group.length && id.includes( group ) ) {
|
||||
value = '';
|
||||
} else if ( $( this ).is( ':checked' ) ) {
|
||||
var truthy = [ 1, '1', 'on' ],
|
||||
inArray = truthy.indexOf( value );
|
||||
value = ( -1 !== inArray ) ? 'true' : value;
|
||||
} else if ( $( this ).is( ':required' ) ) {
|
||||
value = 'false';
|
||||
} else {
|
||||
value = '';
|
||||
}
|
||||
}
|
||||
if ( 'button' === type ) {
|
||||
value = '';
|
||||
}
|
||||
if ( 'textarea' === type ) {
|
||||
value = '';
|
||||
}
|
||||
if ( value || $( this ).is( ':required' ) ) {
|
||||
output += ' ' + id + '="' + value + '"';
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* We assume that a textarea or wysiwg will be content for a
|
||||
* not self-closing shortcode, so values from either of those
|
||||
* will be handled differently and output within the shortcode tags.
|
||||
*
|
||||
* @param slug
|
||||
* @param modal
|
||||
* @private
|
||||
*/
|
||||
function _getContent( slug, modal ) {
|
||||
var $id = $( '#' + modal ),
|
||||
content = $id.find( 'textarea' ).val();
|
||||
if ( ! content ) {
|
||||
var editor = $id.find( "textarea[id*='" + slug + "']" ).attr( 'id' );
|
||||
if ( editor !== 'undefined' && editor.length ) {
|
||||
content = tinymce.get( editor ).getContent( {format: 'text'} );
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a multi checkbox array to a comma separated string.
|
||||
* Must be defined in the shortcode button args.
|
||||
*
|
||||
* @param fields
|
||||
* @param slug
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
function _getMulti( fields, slug ) {
|
||||
var output = '';
|
||||
$( fields ).each( function ( index, value ) {
|
||||
var id = $( '#' + slug ).find( "[id*='" + value + "']" ),
|
||||
array = [];
|
||||
$( id ).each( function ( index ) {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
array.push( $( this ).val() );
|
||||
}
|
||||
} );
|
||||
output += array.length ? ' ' + value + '="' + array.toString() + '"' : '';
|
||||
} );
|
||||
return output;
|
||||
}
|
||||
|
||||
$( document ).ready( function () {
|
||||
SixTenShortcodesEditor.params = typeof SixTenShortcodes === 'undefined' ? '' : SixTenShortcodes;
|
||||
|
||||
if ( typeof SixTenShortcodesEditor.params !== 'undefined' ) {
|
||||
SixTenShortcodesEditor.init();
|
||||
}
|
||||
} );
|
||||
})( document, jQuery );
|
||||
@@ -0,0 +1 @@
|
||||
!function(t,e,i){"use strict";function n(t){var n=[];return e(t).each(function(t){var r=e(this).attr("id");i!==r&&(n[r]=e(this).val()),e(this).is(":checked")&&(n[r]="checked")}),n}function r(t,i){var n="";return e(t).each(function(t){var r=e(this).attr("id"),a=e(this).val(),c=this.type;if(r){var o=r.substr(r.lastIndexOf("-")+1);if(o.includes("nonce")&&(a=""),"checkbox"===c)if(i.length&&o.includes(i))a="";else if(e(this).is(":checked")){var s=[1,"1","on"],d=s.indexOf(a);a=-1!==d?"true":a}else a=e(this).is(":required")?"false":"";"button"===c&&(a=""),"textarea"===c&&(a=""),(a||e(this).is(":required"))&&(n+=" "+o+'="'+a+'"')}}),n}function a(t,i){var n=e("#"+i),r=n.find("textarea").val();if(!r){var a=n.find("textarea[id*='"+t+"']").attr("id");"undefined"!==a&&a.length&&(r=tinymce.get(a).getContent({format:"text"}))}return r}function c(t,i){var n="";return e(t).each(function(t,r){var a=e("#"+i).find("[id*='"+r+"']"),c=[];e(a).each(function(t){e(this).is(":checked")&&c.push(e(this).val())}),n+=c.length?" "+r+'="'+c.toString()+'"':""}),n}var o={};o.init=function(){Object.keys(o.params).forEach(function(i){function s(i){i.preventDefault(),v=i.target,m=!0,e(k).show(),e(".media-modal-close, .media-modal-backdrop, .sixtenpress-cancel-insertion").click(u),e(t).on("keydown",function(t){27===t.keyCode&&m&&u(t)})}function d(t){if(t.preventDefault(),e(v).hasClass(p.button)){var i=r(x,p.group),n=p.group?c(p.group,p.slug):"",o="";i&&(o="["+p.shortcode+n+i+"]",p.self||(o+=a(p.slug,p.modal)+"[/"+p.shortcode+"]"),tinymce.get(e(v).attr("data-editor")).execCommand("mceInsertContent",!1,o))}u(t)}function u(t){t.preventDefault(),e(k).hide(),f(),v=m=!1}function f(){e(x).each(function(t){var i=e(this).attr("id");if("checkbox"===this.type){var n="checked"===g[i];e(this).attr("checked",n)}else e(this).val(g[i])}),e(k+" .upload-file-preview").remove(),h(),l()}function h(){var t=e(k).find(".wp-picker-container");t.length&&t.each(function(){var t=e(this).parent();t.html(t.find('input[type="text"].color-field').attr("style","")),t.find('input[type="text"].wp-color-picker').each(function(){var t=e(this),i=t.data("colorpicker")||{};t.wpColorPicker(e.extend({},!1,i))})})}function l(){var t=e(k).find("textarea[id*='"+p.slug+"']");if(t.length){var i=t.attr("id");tinymce.get(i).setContent("")}}if(o.params.hasOwnProperty(i)){var p=o.params[i],v=!1,m=!1,k="."+p.modal,x=e("#"+p.modal).find(":input"),g=n(x);e("."+p.button).click(s),e(".sixtenpress-default-ui .sixtenpress-insert").click(d)}})},e(t).ready(function(){o.params="undefined"==typeof SixTenShortcodes?"":SixTenShortcodes,void 0!==o.params&&o.init()})}(document,jQuery);
|
||||
@@ -0,0 +1,40 @@
|
||||
<div class="sixtenpress-default-ui <?php echo esc_attr( $this->shortcode_args['modal'] ); ?>"
|
||||
id="<?php echo esc_attr( $this->shortcode_args['modal'] ); ?>" style="display: none;">
|
||||
<div class="media-modal wp-core-ui">
|
||||
<div class="media-modal-content">
|
||||
<button class="media-modal-close">
|
||||
<span class="media-modal-icon">
|
||||
<span class="screen-reader-text"><?php echo esc_html( $this->shortcode_args['labels']['close'] ); ?></span>
|
||||
</span>
|
||||
</button>
|
||||
<div class="media-frame wp-core-ui hide-menu hide-router sixtenpress-meta-wrap">
|
||||
<div class="media-frame-title">
|
||||
<h1><?php echo esc_attr( $this->shortcode_args['labels']['title'] ); ?></h1>
|
||||
</div>
|
||||
<div class="media-frame-content">
|
||||
<?php
|
||||
do_action( 'sixtenpress_shortcode_modal', $this->shortcode );
|
||||
do_action( "sixtenpress_shortcode_modal_{$this->shortcode}", $this->shortcode );
|
||||
?>
|
||||
</div>
|
||||
<div class="media-frame-toolbar">
|
||||
<div class="media-toolbar">
|
||||
<div class="media-toolbar-secondary">
|
||||
<button class="sixtenpress-cancel-insertion button media-button button-large button-secondary media-button-insert"
|
||||
title="<?php echo esc_attr( $this->shortcode_args['labels']['cancel'] ) ?>">
|
||||
<?php echo esc_attr( $this->shortcode_args['labels']['cancel'] ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="media-toolbar-primary">
|
||||
<button class="sixtenpress-insert button media-button button-large button-primary media-button-insert"
|
||||
title="<?php echo esc_attr( $this->shortcode_args['labels']['insert'] ); ?>">
|
||||
<?php echo esc_attr( $this->shortcode_args['labels']['insert'] ); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="media-modal-backdrop"></div>
|
||||
</div>
|
||||
@@ -0,0 +1,29 @@
|
||||
# Copyright (C) 2017 A drop in class for adding shortcode buttons to the editor.
|
||||
# This file is distributed under the same license as the A drop in class for adding shortcode buttons to the editor. package.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: A drop in class for adding shortcode buttons to the editor.\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#: includes/class-sixtenpress-shortcodes.php:111
|
||||
msgid "Add Element"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-sixtenpress-shortcodes.php:115
|
||||
msgid "Create"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-sixtenpress-shortcodes.php:116
|
||||
msgid "Close"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-sixtenpress-shortcodes.php:117
|
||||
msgid "Cancel"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-sixtenpress-shortcodes.php:118
|
||||
msgid "Insert"
|
||||
msgstr ""
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SixTenPressShortcodes loader
|
||||
*
|
||||
* Handles checking for and smartly loading the newest version of this library.
|
||||
*
|
||||
* @category WordPressLibrary
|
||||
* @package SixTenPressShortcodes
|
||||
* @author Robin Cornett <hello@robincornett.com>
|
||||
* @copyright 2016 Robin Cornett <hello@robincornett.com>
|
||||
* @license GPL-2.0+
|
||||
* @version 0.3.2
|
||||
* @link https://gitlab.com/robincornett/sixtenpress-shortcodes
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copyright (c) 2017 Robin Cornett (email : hello@robincornett.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License, version 2 or, at
|
||||
* your discretion, any later version, as published by the Free
|
||||
* Software Foundation.
|
||||
*
|
||||
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Loader versioning: http://jtsternberg.github.io/wp-lib-loader/
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'SixTenPressShortcodes_032', false ) ) {
|
||||
|
||||
/**
|
||||
* Versioned loader class-name
|
||||
*
|
||||
* This ensures each version is loaded/checked.
|
||||
*
|
||||
* @category WordPressLibrary
|
||||
* @package SixTenPressShortcodes
|
||||
* @author Robin Cornett <hello@robincornett.com>
|
||||
* @license GPL-2.0+
|
||||
* @version 0.3.2
|
||||
* @link https://gitlab.com/robincornett/sixtenpress-shortcodes
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class SixTenPressShortcodes_032 {
|
||||
|
||||
/**
|
||||
* SixTenPressShortcodes version number
|
||||
* @var string
|
||||
* @since 0.1.0
|
||||
*/
|
||||
const VERSION = '0.3.2';
|
||||
|
||||
/**
|
||||
* Current version hook priority.
|
||||
* Will decrement with each release
|
||||
*
|
||||
* @var int
|
||||
* @since 0.1.0
|
||||
*/
|
||||
const PRIORITY = 9992;
|
||||
|
||||
/**
|
||||
* Starts the version checking process.
|
||||
* Creates SIXTENPRESSSHORTCODES_LOADED definition for early detection by
|
||||
* other scripts.
|
||||
*
|
||||
* Hooks SixTenPressShortcodes inclusion to the sixtenpressshortcodes_load hook
|
||||
* on a high priority which decrements (increasing the priority) with
|
||||
* each version release.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public function __construct() {
|
||||
if ( ! defined( 'SIXTENPRESSSHORTCODES_LOADED' ) ) {
|
||||
/**
|
||||
* A constant you can use to check if SixTenPressShortcodes is loaded
|
||||
* for your plugins/themes with SixTenPressShortcodes dependency.
|
||||
*
|
||||
* Can also be used to determine the priority of the hook
|
||||
* in use for the currently loaded version.
|
||||
*/
|
||||
define( 'SIXTENPRESSSHORTCODES_LOADED', self::PRIORITY );
|
||||
}
|
||||
|
||||
// Use the hook system to ensure only the newest version is loaded.
|
||||
add_action( 'sixtenpressshortcodes_load', array( $this, 'include_lib' ), self::PRIORITY );
|
||||
|
||||
/*
|
||||
* Hook in to the first hook we have available and
|
||||
* fire our `sixtenpressshortcodes_load' hook.
|
||||
*/
|
||||
add_action( 'muplugins_loaded', array( __CLASS__, 'fire_hook' ), 9 );
|
||||
add_action( 'plugins_loaded', array( __CLASS__, 'fire_hook' ), 9 );
|
||||
add_action( 'after_setup_theme', array( __CLASS__, 'fire_hook' ), 9 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires the sixtenpressshortcodes_load action hook.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static function fire_hook() {
|
||||
if ( ! did_action( 'sixtenpressshortcodes_load' ) ) {
|
||||
// Then fire our hook.
|
||||
do_action( 'sixtenpressshortcodes_load' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A final check if SixTenPressShortcodes exists before kicking off
|
||||
* our SixTenPressShortcodes loading.
|
||||
*
|
||||
* SIXTENPRESSSHORTCODES_VERSION and SIXTENPRESSSHORTCODES_DIR constants are
|
||||
* set at this point.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public function include_lib() {
|
||||
if ( class_exists( 'SixTenPressShortcodes', false ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! defined( 'SIXTENPRESSSHORTCODES_VERSION' ) ) {
|
||||
/**
|
||||
* Defines the currently loaded version of SixTenPressShortcodes.
|
||||
*/
|
||||
define( 'SIXTENPRESSSHORTCODES_VERSION', self::VERSION );
|
||||
}
|
||||
|
||||
if ( ! defined( 'SIXTENPRESSSHORTCODES_DIR' ) ) {
|
||||
/**
|
||||
* Defines the directory of the currently loaded version of SixTenPressShortcodes.
|
||||
*/
|
||||
define( 'SIXTENPRESSSHORTCODES_DIR', dirname( __FILE__ ) . '/' );
|
||||
}
|
||||
|
||||
// Include and initiate SixTenPressShortcodes.
|
||||
require_once SIXTENPRESSSHORTCODES_DIR . 'includes/class-sixtenpress-shortcodes.php';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Kick it off.
|
||||
new SixTenPressShortcodes_032();
|
||||
}
|
||||
@@ -6,6 +6,8 @@
|
||||
class DisplayFeaturedImageGenesisWidgetsShortcodes {
|
||||
|
||||
/**
|
||||
* Build the featured author widget shortcode.
|
||||
*
|
||||
* @param $atts
|
||||
*
|
||||
* @return string
|
||||
@@ -20,6 +22,8 @@ class DisplayFeaturedImageGenesisWidgetsShortcodes {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the featured post type widget shortcode.
|
||||
*
|
||||
* @param $atts
|
||||
*
|
||||
* @return string
|
||||
@@ -34,6 +38,8 @@ class DisplayFeaturedImageGenesisWidgetsShortcodes {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the featured term widget shortcode.
|
||||
*
|
||||
* @param $atts
|
||||
*
|
||||
* @return string
|
||||
@@ -48,6 +54,68 @@ class DisplayFeaturedImageGenesisWidgetsShortcodes {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add media shortcode buttons to the editor.
|
||||
*/
|
||||
public function shortcode_buttons() {
|
||||
$widgets = array(
|
||||
'displayfeaturedimagegenesis_term' => __( 'Add Featured Term Widget', 'display-featured-image-genesis' ),
|
||||
'displayfeaturedimagegenesis_author' => __( 'Add Featured Author Widget', 'display-featured-image-genesis' ),
|
||||
'displayfeaturedimagegenesis_post_type' => __( 'Add Featured Post Type Widget', 'display-featured-image-genesis' ),
|
||||
);
|
||||
$setting = displayfeaturedimagegenesis_get_setting();
|
||||
foreach ( $widgets as $widget => $button_label ) {
|
||||
if ( ! $setting['shortcode'][ $widget ] ) {
|
||||
continue;
|
||||
}
|
||||
sixtenpress_shortcode_register( $widget, array(
|
||||
'modal' => $widget,
|
||||
'button' => array(
|
||||
'id' => "{$widget}-create",
|
||||
'class' => "{$widget}-create",
|
||||
'label' => $button_label,
|
||||
),
|
||||
'self' => true,
|
||||
'labels' => array(
|
||||
'title' => __( 'Create Widget', 'display-featured-image-genesis' ),
|
||||
'insert' => __( 'Insert Widget', 'display-featured-image-genesis' ),
|
||||
),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the widget forms to the modal.
|
||||
* @param $shortcode
|
||||
*/
|
||||
public function do_modal( $shortcode ) {
|
||||
$widgets = array(
|
||||
'displayfeaturedimagegenesis_term' => 'Display_Featured_Image_Genesis_Widget_Taxonomy',
|
||||
'displayfeaturedimagegenesis_author' => 'Display_Featured_Image_Genesis_Author_Widget',
|
||||
'displayfeaturedimagegenesis_post_type' => 'Display_Featured_Image_Genesis_Widget_CPT',
|
||||
);
|
||||
foreach ( $widgets as $shortcode_text => $widget ) {
|
||||
if ( $shortcode_text === $shortcode ) {
|
||||
$class = new $widget();
|
||||
$class->form( array() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify our modals' CSS.
|
||||
*
|
||||
* @param $css
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function inline_css( $css ) {
|
||||
return '.displayfeaturedimagegenesis_term .media-modal-content, .displayfeaturedimagegenesis_post_type .media-modal-content {max-width: 500px;max-height:475px;}
|
||||
.displayfeaturedimagegenesis_author .media-modal-content {max-width: 300px;}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the widget defaults.
|
||||
*
|
||||
* @param $class
|
||||
*
|
||||
* @return mixed
|
||||
@@ -59,6 +127,7 @@ class DisplayFeaturedImageGenesisWidgetsShortcodes {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the shortcode output.
|
||||
* @param $atts
|
||||
* @param $class
|
||||
*
|
||||
@@ -76,6 +145,8 @@ class DisplayFeaturedImageGenesisWidgetsShortcodes {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the shortcode.
|
||||
*
|
||||
* @param $atts
|
||||
* @param $class
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user