From 5a3b21a68b5746605ee2e06850362d3d4ff78b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Humbert?= Date: Tue, 23 Jan 2018 14:58:23 +0100 Subject: [PATCH 01/18] Add ability to display posts as a list --- admin/admin.php | 82 ++ admin/ajax.php | 109 ++ admin/butterbean/butterbean.php | 44 + admin/butterbean/changelog.md | 5 + admin/butterbean/class-butterbean.php | 867 +++++++++++++++ admin/butterbean/contributing.md | 31 + admin/butterbean/css/butterbean.css | 330 ++++++ admin/butterbean/css/butterbean.min.css | 1 + admin/butterbean/inc/class-control.php | 399 +++++++ admin/butterbean/inc/class-manager.php | 550 ++++++++++ admin/butterbean/inc/class-section.php | 291 +++++ admin/butterbean/inc/class-setting.php | 226 ++++ .../inc/controls/class-control-checkboxes.php | 43 + .../inc/controls/class-control-color.php | 104 ++ .../inc/controls/class-control-date.php | 135 +++ .../inc/controls/class-control-datetime.php | 140 +++ .../inc/controls/class-control-excerpt.php | 82 ++ .../inc/controls/class-control-image.php | 112 ++ .../controls/class-control-multi-avatars.php | 90 ++ .../inc/controls/class-control-palette.php | 51 + .../inc/controls/class-control-parent.php | 97 ++ .../controls/class-control-radio-image.php | 46 + .../inc/controls/class-control-radio.php | 46 + .../controls/class-control-select-group.php | 53 + .../inc/controls/class-control-textarea.php | 42 + admin/butterbean/inc/functions-core.php | 169 +++ .../inc/settings/class-setting-array.php | 80 ++ .../inc/settings/class-setting-date.php | 105 ++ .../inc/settings/class-setting-datetime.php | 105 ++ .../inc/settings/class-setting-multiple.php | 154 +++ admin/butterbean/js/butterbean.js | 875 +++++++++++++++ admin/butterbean/js/butterbean.min.js | 1 + admin/butterbean/license.md | 339 ++++++ admin/butterbean/readme.md | 152 +++ admin/butterbean/screenshot-1.png | Bin 0 -> 21854 bytes admin/butterbean/tmpl/control-checkbox.php | 11 + admin/butterbean/tmpl/control-checkboxes.php | 22 + admin/butterbean/tmpl/control-color.php | 11 + admin/butterbean/tmpl/control-date.php | 55 + admin/butterbean/tmpl/control-datetime.php | 55 + admin/butterbean/tmpl/control-image.php | 24 + .../butterbean/tmpl/control-multi-avatars.php | 23 + admin/butterbean/tmpl/control-palette.php | 23 + admin/butterbean/tmpl/control-parent.php | 17 + admin/butterbean/tmpl/control-radio-image.php | 17 + admin/butterbean/tmpl/control-radio.php | 22 + .../butterbean/tmpl/control-select-group.php | 33 + admin/butterbean/tmpl/control-select.php | 20 + admin/butterbean/tmpl/control-textarea.php | 11 + admin/butterbean/tmpl/control.php | 11 + admin/butterbean/tmpl/manager.php | 2 + admin/butterbean/tmpl/nav.php | 1 + admin/butterbean/tmpl/section.php | 3 + admin/css/admin.css | 46 + admin/images/spinner.gif | Bin 0 -> 4162 bytes admin/js/admin-scripts.js | 254 +++++ admin/js/button.js | 42 + admin/metabox.php | 993 ++++++++++++++++++ admin/post-type.php | 62 ++ admin/widget.php | 112 ++ css/wp-show-posts-min.css | 1 + css/wp-show-posts.css | 265 +++++ inc/compat.php | 46 + inc/defaults.php | 65 ++ inc/deprecated.php | 10 + inc/functions.php | 395 +++++++ inc/image-resizer.php | 244 +++++ inc/styling.php | 59 ++ js/jquery.matchHeight.js | 399 +++++++ license.txt | 29 + readme.txt | 334 ++++++ wp-show-posts.php | 571 ++++++++++ 72 files changed, 10244 insertions(+) create mode 100644 admin/admin.php create mode 100644 admin/ajax.php create mode 100644 admin/butterbean/butterbean.php create mode 100644 admin/butterbean/changelog.md create mode 100644 admin/butterbean/class-butterbean.php create mode 100644 admin/butterbean/contributing.md create mode 100644 admin/butterbean/css/butterbean.css create mode 100644 admin/butterbean/css/butterbean.min.css create mode 100644 admin/butterbean/inc/class-control.php create mode 100644 admin/butterbean/inc/class-manager.php create mode 100644 admin/butterbean/inc/class-section.php create mode 100644 admin/butterbean/inc/class-setting.php create mode 100644 admin/butterbean/inc/controls/class-control-checkboxes.php create mode 100644 admin/butterbean/inc/controls/class-control-color.php create mode 100644 admin/butterbean/inc/controls/class-control-date.php create mode 100644 admin/butterbean/inc/controls/class-control-datetime.php create mode 100644 admin/butterbean/inc/controls/class-control-excerpt.php create mode 100644 admin/butterbean/inc/controls/class-control-image.php create mode 100644 admin/butterbean/inc/controls/class-control-multi-avatars.php create mode 100644 admin/butterbean/inc/controls/class-control-palette.php create mode 100644 admin/butterbean/inc/controls/class-control-parent.php create mode 100644 admin/butterbean/inc/controls/class-control-radio-image.php create mode 100644 admin/butterbean/inc/controls/class-control-radio.php create mode 100644 admin/butterbean/inc/controls/class-control-select-group.php create mode 100644 admin/butterbean/inc/controls/class-control-textarea.php create mode 100644 admin/butterbean/inc/functions-core.php create mode 100644 admin/butterbean/inc/settings/class-setting-array.php create mode 100644 admin/butterbean/inc/settings/class-setting-date.php create mode 100644 admin/butterbean/inc/settings/class-setting-datetime.php create mode 100644 admin/butterbean/inc/settings/class-setting-multiple.php create mode 100644 admin/butterbean/js/butterbean.js create mode 100644 admin/butterbean/js/butterbean.min.js create mode 100644 admin/butterbean/license.md create mode 100644 admin/butterbean/readme.md create mode 100644 admin/butterbean/screenshot-1.png create mode 100644 admin/butterbean/tmpl/control-checkbox.php create mode 100644 admin/butterbean/tmpl/control-checkboxes.php create mode 100644 admin/butterbean/tmpl/control-color.php create mode 100644 admin/butterbean/tmpl/control-date.php create mode 100644 admin/butterbean/tmpl/control-datetime.php create mode 100644 admin/butterbean/tmpl/control-image.php create mode 100644 admin/butterbean/tmpl/control-multi-avatars.php create mode 100644 admin/butterbean/tmpl/control-palette.php create mode 100644 admin/butterbean/tmpl/control-parent.php create mode 100644 admin/butterbean/tmpl/control-radio-image.php create mode 100644 admin/butterbean/tmpl/control-radio.php create mode 100644 admin/butterbean/tmpl/control-select-group.php create mode 100644 admin/butterbean/tmpl/control-select.php create mode 100644 admin/butterbean/tmpl/control-textarea.php create mode 100644 admin/butterbean/tmpl/control.php create mode 100644 admin/butterbean/tmpl/manager.php create mode 100644 admin/butterbean/tmpl/nav.php create mode 100644 admin/butterbean/tmpl/section.php create mode 100644 admin/css/admin.css create mode 100644 admin/images/spinner.gif create mode 100644 admin/js/admin-scripts.js create mode 100644 admin/js/button.js create mode 100644 admin/metabox.php create mode 100644 admin/post-type.php create mode 100644 admin/widget.php create mode 100644 css/wp-show-posts-min.css create mode 100644 css/wp-show-posts.css create mode 100644 inc/compat.php create mode 100644 inc/defaults.php create mode 100644 inc/deprecated.php create mode 100644 inc/functions.php create mode 100644 inc/image-resizer.php create mode 100644 inc/styling.php create mode 100644 js/jquery.matchHeight.js create mode 100644 license.txt create mode 100644 readme.txt create mode 100644 wp-show-posts.php diff --git a/admin/admin.php b/admin/admin.php new file mode 100644 index 0000000..ec28392 --- /dev/null +++ b/admin/admin.php @@ -0,0 +1,82 @@ + ( isset( $post ) ) ? $post->ID : false, + 'nonce' => wp_create_nonce( 'wpsp_nonce' ) + )); + } + + wp_enqueue_style( 'wpsp-admin', plugin_dir_url( __FILE__ ) . "css/admin.css", array(), WPSP_VERSION ); + } +} + +if ( ! function_exists( 'wpsp_translatable_strings' ) ) { + add_action( 'admin_head','wpsp_translatable_strings', 0 ); + /** + * Add some javascript variables to the admin head + * @since 0.1 + */ + function wpsp_translatable_strings() { + ?> + + 0 ) { + foreach ( $terms as $term ) { + $types[] = $term->slug; + } + } + + echo wp_json_encode( $types ); + + die(); + } +} + +if ( ! function_exists( 'wpsp_get_taxonomies' ) ) { + add_action( 'wp_ajax_wpsp_get_taxonomies', 'wpsp_get_taxonomies' ); + /** + * Get out taxonomies based on the set post type + * @since 0.1 + */ + function wpsp_get_taxonomies() { + if ( ! isset( $_POST[ 'wpsp_nonce' ] ) || ! wp_verify_nonce( $_POST[ 'wpsp_nonce' ], 'wpsp_nonce' ) ) { + wp_die( 'Permission declined' ); + } + + $terms = get_object_taxonomies( sanitize_text_field( $_POST[ 'post_type' ] ) ); + $count = count( $terms ); + $types = array(); + if ( $count > 0 ) { + foreach ( $terms as $term ) { + $types[] = $term; + } + } + + echo wp_json_encode( $types ); + + die(); + } +} + +if ( ! function_exists( 'wpsp_get_post_lists' ) ) { + add_action( 'wp_ajax_wpsp_get_post_lists', 'wpsp_get_post_lists' ); + /** + * Get all of our post lists + * @since 0.1 + */ + function wpsp_get_post_lists() { + if ( ! isset( $_POST[ 'wpsp_nonce' ] ) || ! wp_verify_nonce( $_POST[ 'wpsp_nonce' ], 'wpsp_nonce' ) ) { + wp_die( 'Permission declined' ); + } + + $args = array( + 'posts_per_page' => -1, + 'post_type' => 'wp_show_posts', + 'post_status' => 'publish', + 'showposts' => -1 + ); + $posts = get_posts( $args ); + + $count = count( $posts ); + $types = array(); + if ( $count > 0 ) { + foreach ( $posts as $post ) { + $types[] = array( 'text' => $post->post_title, 'value' => $post->ID ); + } + } + + echo wp_json_encode( $types ); + + die(); + } +} diff --git a/admin/butterbean/butterbean.php b/admin/butterbean/butterbean.php new file mode 100644 index 0000000..bd83968 --- /dev/null +++ b/admin/butterbean/butterbean.php @@ -0,0 +1,44 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +// For each version release, the priority needs to decrement by 1. This is so that +// we can load newer versions earlier than older versions when there's a conflict. +add_action( 'init', 'butterbean_loader_100', 9999 ); + +if ( ! function_exists( 'butterbean_loader_100' ) ) { + + /** + * Loader function. Note to change the name of this function to use the + * current version number of the plugin. `1.0.0` is `100`, `1.3.4` = `134`. + * + * @since 1.0.0 + * @access public + * @return void + */ + function butterbean_loader_100() { + + // If not in the admin, bail. + if ( ! is_admin() ) + return; + + // If ButterBean hasn't been loaded, let's load it. + if ( ! defined( 'BUTTERBEAN_LOADED' ) ) { + define( 'BUTTERBEAN_LOADED', true ); + + require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-butterbean.php' ); + } + } +} diff --git a/admin/butterbean/changelog.md b/admin/butterbean/changelog.md new file mode 100644 index 0000000..fe10399 --- /dev/null +++ b/admin/butterbean/changelog.md @@ -0,0 +1,5 @@ +# Change Log + +## [1.0.0] - 2016-08-29 + +* Plugin launch. Everything's new! diff --git a/admin/butterbean/class-butterbean.php b/admin/butterbean/class-butterbean.php new file mode 100644 index 0000000..94ce2a1 --- /dev/null +++ b/admin/butterbean/class-butterbean.php @@ -0,0 +1,867 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +if ( ! class_exists( 'ButterBean' ) ) { + + /** + * Main ButterBean class. Runs the show. + * + * @since 1.0.0 + * @access public + */ + final class ButterBean { + + /** + * Directory path to the plugin folder. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $dir_path = ''; + + /** + * Directory URI to the plugin folder. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $dir_uri = ''; + + /** + * Directory path to the template folder. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $tmpl_path = ''; + + /** + * Array of managers. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $managers = array(); + + /** + * Array of manager types. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $manager_types = array(); + + /** + * Array of section types. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $section_types = array(); + + /** + * Array of control types. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $control_types = array(); + + /** + * Array of setting types. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $setting_types = array(); + + /** + * Whether this is a new post. Once the post is saved and we're + * no longer on the `post-new.php` screen, this is going to be + * `false`. + * + * @since 1.0.0 + * @access public + * @var bool + */ + public $is_new_post = false; + + /** + * Returns the instance. + * + * @since 1.0.0 + * @access public + * @return object + */ + public static function get_instance() { + + static $instance = null; + + if ( is_null( $instance ) ) { + $instance = new self; + $instance->setup(); + $instance->includes(); + $instance->setup_actions(); + } + + return $instance; + } + + /** + * Constructor method. + * + * @since 1.0.0 + * @access private + * @return void + */ + private function __construct() {} + + /** + * Initial plugin setup. + * + * @since 1.0.0 + * @access private + * @return void + */ + private function setup() { + + $this->dir_path = apply_filters( 'butterbean_dir_path', trailingslashit( plugin_dir_path( __FILE__ ) ) ); + $this->dir_uri = apply_filters( 'butterbean_dir_uri', trailingslashit( plugin_dir_url( __FILE__ ) ) ); + + $this->tmpl_path = trailingslashit( $this->dir_path . 'tmpl' ); + } + + /** + * Loads include and admin files for the plugin. + * + * @since 1.0.0 + * @access private + * @return void + */ + private function includes() { + + // If not in the admin, bail. + if ( ! is_admin() ) + return; + + // Load base classes. + require_once( $this->dir_path . 'inc/class-manager.php' ); + require_once( $this->dir_path . 'inc/class-section.php' ); + require_once( $this->dir_path . 'inc/class-control.php' ); + require_once( $this->dir_path . 'inc/class-setting.php' ); + + // Load control sub-classes. + require_once( $this->dir_path . 'inc/controls/class-control-checkboxes.php' ); + require_once( $this->dir_path . 'inc/controls/class-control-color.php' ); + require_once( $this->dir_path . 'inc/controls/class-control-datetime.php' ); + require_once( $this->dir_path . 'inc/controls/class-control-image.php' ); + require_once( $this->dir_path . 'inc/controls/class-control-palette.php' ); + require_once( $this->dir_path . 'inc/controls/class-control-radio.php' ); + require_once( $this->dir_path . 'inc/controls/class-control-radio-image.php' ); + require_once( $this->dir_path . 'inc/controls/class-control-select-group.php' ); + require_once( $this->dir_path . 'inc/controls/class-control-textarea.php' ); + + require_once( $this->dir_path . 'inc/controls/class-control-excerpt.php' ); + require_once( $this->dir_path . 'inc/controls/class-control-multi-avatars.php' ); + require_once( $this->dir_path . 'inc/controls/class-control-parent.php' ); + + // Load setting sub-classes. + require_once( $this->dir_path . 'inc/settings/class-setting-multiple.php' ); + require_once( $this->dir_path . 'inc/settings/class-setting-datetime.php' ); + require_once( $this->dir_path . 'inc/settings/class-setting-array.php' ); + + // Load functions. + require_once( $this->dir_path . 'inc/functions-core.php' ); + } + + /** + * Sets up initial actions. + * + * @since 1.0.0 + * @access private + * @return void + */ + private function setup_actions() { + + // Call the register function. + add_action( 'load-post.php', array( $this, 'register' ), 95 ); + add_action( 'load-post-new.php', array( $this, 'register' ), 95 ); + + // Register default types. + add_action( 'butterbean_register', array( $this, 'register_manager_types' ), -95 ); + add_action( 'butterbean_register', array( $this, 'register_section_types' ), -95 ); + add_action( 'butterbean_register', array( $this, 'register_control_types' ), -95 ); + add_action( 'butterbean_register', array( $this, 'register_setting_types' ), -95 ); + } + + /** + * Registration callback. Fires the `butterbean_register` action hook to + * allow plugins to register their managers. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function register() { + + // If this is a new post, set the new post boolean. + if ( 'load-post-new.php' === current_action() ) + $this->is_new_post = true; + + // Get the current post type. + $post_type = get_current_screen()->post_type; + + // Action hook for registering managers. + do_action( 'butterbean_register', $this, $post_type ); + + // Loop through the managers to see if we're using on on this screen. + foreach ( $this->managers as $manager ) { + + // If we found a matching post type, add our actions/filters. + if ( ! in_array( $post_type, (array) $manager->post_type ) ) { + $this->unregister_manager( $manager->name ); + continue; + } + + // Sort controls and sections by priority. + uasort( $manager->controls, array( $this, 'priority_sort' ) ); + uasort( $manager->sections, array( $this, 'priority_sort' ) ); + } + + // If no managers registered, bail. + if ( ! $this->managers ) + return; + + // Add meta boxes. + add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 5 ); + + // Save settings. + add_action( 'save_post', array( $this, 'update' ) ); + + // Load scripts and styles. + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_action( 'butterbean_enqueue_scripts', array( $this, 'enqueue' ) ); + + // Localize scripts and Undescore templates. + add_action( 'admin_footer', array( $this, 'localize_scripts' ) ); + add_action( 'admin_footer', array( $this, 'print_templates' ) ); + + // Renders our Backbone views. + add_action( 'admin_print_footer_scripts', array( $this, 'render_views' ), 95 ); + } + + /** + * Register a manager. + * + * @since 1.0.0 + * @access public + * @param object|string $manager + * @param array $args + * @return void + */ + public function register_manager( $manager, $args = array() ) { + + if ( ! is_object( $manager ) ) { + + $type = isset( $args['type'] ) ? $this->get_manager_type( $args['type'] ) : $this->get_manager_type( 'default' ); + + $manager = new $type( $manager, $args ); + } + + if ( ! $this->manager_exists( $manager->name ) ) + $this->managers[ $manager->name ] = $manager; + + return $manager; + } + + /** + * Unregisters a manager object. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return void + */ + public function unregister_manager( $name ) { + + if ( $this->manager_exists( $name ) ) + unset( $this->managers[ $name ] ); + } + + /** + * Returns a manager object. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return object|bool + */ + public function get_manager( $name ) { + + return $this->manager_exists( $name ) ? $this->managers[ $name ] : false; + } + + /** + * Checks if a manager exists. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return bool + */ + public function manager_exists( $name ) { + + return isset( $this->managers[ $name ] ); + } + + /** + * Registers a manager type. This is just a method of telling ButterBean + * the class of your custom manager type. It allows the manager to be + * called without having to pass an object to `register_manager()`. + * + * @since 1.0.0 + * @access public + * @param string $type + * @param string $class + * @return void + */ + public function register_manager_type( $type, $class ) { + + if ( ! $this->manager_type_exists( $type ) ) + $this->manager_types[ $type ] = $class; + } + + /** + * Unregisters a manager type. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return void + */ + public function unregister_manager_type( $type ) { + + if ( $this->manager_type_exists( $type ) ) + unset( $this->manager_types[ $type ] ); + } + + /** + * Returns the class name for the manager type. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return string + */ + public function get_manager_type( $type ) { + + return $this->manager_type_exists( $type ) ? $this->manager_types[ $type ] : $this->manager_types[ 'default' ]; + } + + /** + * Checks if a manager type exists. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return bool + */ + public function manager_type_exists( $type ) { + + return isset( $this->manager_types[ $type ] ); + } + + /** + * Registers a section type. This is just a method of telling ButterBean + * the class of your custom section type. It allows the section to be + * called without having to pass an object to `register_section()`. + * + * @since 1.0.0 + * @access public + * @param string $type + * @param string $class + * @return void + */ + public function register_section_type( $type, $class ) { + + if ( ! $this->section_type_exists( $type ) ) + $this->section_types[ $type ] = $class; + } + + /** + * Unregisters a section type. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return void + */ + public function unregister_section_type( $type ) { + + if ( $this->section_type_exists( $type ) ) + unset( $this->section_types[ $type ] ); + } + + /** + * Returns the class name for the section type. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return string + */ + public function get_section_type( $type ) { + + return $this->section_type_exists( $type ) ? $this->section_types[ $type ] : $this->section_types[ 'default' ]; + } + + /** + * Checks if a section type exists. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return bool + */ + public function section_type_exists( $type ) { + + return isset( $this->section_types[ $type ] ); + } + + /** + * Registers a control type. This is just a method of telling ButterBean + * the class of your custom control type. It allows the control to be + * called without having to pass an object to `register_control()`. + * + * @since 1.0.0 + * @access public + * @param string $type + * @param string $class + * @return void + */ + public function register_control_type( $type, $class ) { + + if ( ! $this->control_type_exists( $type ) ) + $this->control_types[ $type ] = $class; + } + + /** + * Unregisters a control type. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return void + */ + public function unregister_control_type( $type ) { + + if ( $this->control_type_exists( $type ) ) + unset( $this->control_types[ $type ] ); + } + + /** + * Returns the class name for the control type. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return string + */ + public function get_control_type( $type ) { + + return $this->control_type_exists( $type ) ? $this->control_types[ $type ] : $this->control_types[ 'default' ]; + } + + /** + * Checks if a control type exists. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return bool + */ + public function control_type_exists( $type ) { + + return isset( $this->control_types[ $type ] ); + } + + /** + * Registers a setting type. This is just a method of telling ButterBean + * the class of your custom setting type. It allows the setting to be + * called without having to pass an object to `register_setting()`. + * + * @since 1.0.0 + * @access public + * @param string $type + * @param string $class + * @return void + */ + public function register_setting_type( $type, $class ) { + + if ( ! $this->setting_type_exists( $type ) ) + $this->setting_types[ $type ] = $class; + } + + /** + * Unregisters a setting type. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return void + */ + public function unregister_setting_type( $type ) { + + if ( $this->setting_type_exists( $type ) ) + unset( $this->setting_types[ $type ] ); + } + + /** + * Returns the class name for the setting type. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return string + */ + public function get_setting_type( $type ) { + + return $this->setting_type_exists( $type ) ? $this->setting_types[ $type ] : $this->setting_types[ 'default' ]; + } + + /** + * Checks if a setting type exists. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return bool + */ + public function setting_type_exists( $type ) { + + return isset( $this->setting_types[ $type ] ); + } + + /** + * Registers our manager types so that devs don't have to directly instantiate + * the class each time they register a manager. Instead, they can use the + * `type` argument. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function register_manager_types() { + + $this->register_manager_type( 'default', 'ButterBean_Manager' ); + } + + /** + * Registers our section types so that devs don't have to directly instantiate + * the class each time they register a section. Instead, they can use the + * `type` argument. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function register_section_types() { + + $this->register_section_type( 'default', 'ButterBean_Section' ); + } + + /** + * Registers our control types so that devs don't have to directly instantiate + * the class each time they register a control. Instead, they can use the + * `type` argument. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function register_control_types() { + + $this->register_control_type( 'default', 'ButterBean_Control' ); + $this->register_control_type( 'checkboxes', 'ButterBean_Control_Checkboxes' ); + $this->register_control_type( 'color', 'ButterBean_Control_Color' ); + $this->register_control_type( 'datetime', 'ButterBean_Control_Datetime' ); + $this->register_control_type( 'excerpt', 'ButterBean_Control_Excerpt' ); + $this->register_control_type( 'image', 'ButterBean_Control_Image' ); + $this->register_control_type( 'palette', 'ButterBean_Control_Palette' ); + $this->register_control_type( 'radio', 'ButterBean_Control_Radio' ); + $this->register_control_type( 'radio-image', 'ButterBean_Control_Radio_Image' ); + $this->register_control_type( 'select-group', 'ButterBean_Control_Select_Group' ); + $this->register_control_type( 'textarea', 'ButterBean_Control_Textarea' ); + $this->register_control_type( 'multi-avatars', 'ButterBean_Control_Multi_Avatars' ); + $this->register_control_type( 'parent', 'ButterBean_Control_Parent' ); + } + + /** + * Registers our setting types so that devs don't have to directly instantiate + * the class each time they register a setting. Instead, they can use the + * `type` argument. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function register_setting_types() { + + $this->register_setting_type( 'default', 'ButterBean_Setting' ); + $this->register_setting_type( 'single', 'ButterBean_Setting' ); + $this->register_setting_type( 'multiple', 'ButterBean_Setting_Multiple' ); + $this->register_setting_type( 'array', 'ButterBean_Setting_Array' ); + $this->register_setting_type( 'datetime', 'ButterBean_Setting_Datetime' ); + } + + /** + * Fires an action hook to register/enqueue scripts/styles. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function enqueue_scripts() { + + do_action( 'butterbean_enqueue_scripts' ); + } + + /** + * Loads scripts and styles. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function enqueue() { + $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + + // Enqueue the main plugin script. + wp_enqueue_script( 'butterbean', $this->dir_uri . "js/butterbean{$min}.js", array( 'backbone', 'wp-util' ), '', true ); + + // Enqueue the main plugin style. + wp_enqueue_style( 'butterbean', $this->dir_uri . "css/butterbean{$min}.css" ); + + // Loop through the manager and its controls and call each control's `enqueue()` method. + foreach ( $this->managers as $manager ) { + + $manager->enqueue(); + + foreach ( $manager->sections as $section ) + $section->enqueue(); + + foreach ( $manager->controls as $control ) + $control->enqueue(); + } + } + + /** + * Callback function for adding meta boxes. This function adds a meta box + * for each of the managers. + * + * @since 1.0.0 + * @access public + * @param string $post_type + * @return void + */ + public function add_meta_boxes( $post_type ) { + + foreach ( $this->managers as $manager ) { + + // If the manager is registered for the current post type, add a meta box. + if ( in_array( $post_type, (array) $manager->post_type ) && $manager->check_capabilities() ) { + + add_meta_box( + "butterbean-ui-{$manager->name}", + $manager->label, + array( $this, 'meta_box' ), + $post_type, + $manager->context, + $manager->priority, + array( 'manager' => $manager ) + ); + } + } + } + + /** + * Displays the meta box. Note that the actual content of the meta box is + * handled via Underscore.js templates. The only thing we're outputting here + * is the nonce field. + * + * @since 1.0.0 + * @access public + * @param object $post + * @param array $metabox + * @return void + */ + public function meta_box( $post, $metabox ) { + + $manager = $metabox['args']['manager']; + + $manager->post_id = $this->post_id = $post->ID; + + // Nonce field to validate on save. + wp_nonce_field( "butterbean_{$manager->name}_nonce", "butterbean_{$manager->name}" ); + } + + /** + * Passes the appropriate section and control json data to the JS file. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function localize_scripts() { + + $json = array( 'managers' => array() ); + + foreach ( $this->managers as $manager ) { + + if ( $manager->check_capabilities() ) + $json['managers'][] = $manager->get_json(); + } + + wp_localize_script( 'butterbean', 'butterbean_data', $json ); + } + + /** + * Prints the Underscore.js templates. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function print_templates() { + + $m_templates = array(); + $s_templates = array(); + $c_templates = array(); ?> + + + + managers as $manager ) { + + if ( ! $manager->check_capabilities() ) + continue; + + if ( ! in_array( $manager->type, $m_templates ) ) { + $m_templates[] = $manager->type; + + $manager->print_template(); + } + + foreach ( $manager->sections as $section ) { + + if ( ! in_array( $section->type, $s_templates ) ) { + $s_templates[] = $section->type; + + $section->print_template(); + } + } + + foreach ( $manager->controls as $control ) { + + if ( ! in_array( $control->type, $c_templates ) ) { + $c_templates[] = $control->type; + + $control->print_template(); + } + } + } + } + + /** + * Renders our Backbone views. We're calling this late in the page load so + * that other scripts have an opportunity to extend with their own, custom + * views for custom controls and such. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function render_views() { ?> + + + managers as $manager ) { + + if ( $manager->check_capabilities() ) + $manager->save( $post_id ); + } + } + + /** + * Helper method for sorting sections and controls by priority. + * + * @since 1.0.0 + * @access protected + * @param object $a + * @param object $b + * @return int + */ + protected function priority_sort( $a, $b ) { + + if ( $a->priority === $b->priority ) + return $a->instance_number - $b->instance_number; + + return $a->priority - $b->priority; + } + } + + /** + * Gets the instance of the `ButterBean` class. This function is useful for quickly grabbing data + * used throughout the plugin. + * + * @since 1.0.0 + * @access public + * @return object + */ + function butterbean() { + return ButterBean::get_instance(); + } + + // Let's do this thang! + butterbean(); +} diff --git a/admin/butterbean/contributing.md b/admin/butterbean/contributing.md new file mode 100644 index 0000000..1a1cc98 --- /dev/null +++ b/admin/butterbean/contributing.md @@ -0,0 +1,31 @@ +# Contributing + +The code for the project is handled via its [GitHub Repository](https://github.com/justintadlock/butterbean). You can open tickets, create patches, and send pull requests there. + +## Pull requests + +Problem first. Solution second. + +Pull requests should have a ticket open for discussion first. I rarely accept pull requests that aren't for a specific issue for various reasons. It's far better to post an issue and let me or the community provide feedback prior to creating a pull request. + +Please don't make pull requests against the `master` branch. This is the latest, stable code. You can make a pull request against one of the point branches or the `dev` (future release) branch. + +## Coding standards + +In general, the project follows all WordPress [coding standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards). There are instances where it doesn't, opting for personal choices of my own, but in terms of contributing, following the WordPress standards is best practice. + +## Script and style files + +The project consists of several script and style files. When making patches or pull requests with changes to these files, only do so to the primary file. Don't create patches for the minified (`.min`) versions of the files. Those will be minified after a patch is merged into the code base. + +## Language + +All text strings follow U.S. English by default. While such guides are generally unneeded, in cases where style considerations are necessary, these will typically follow conventions laid out in *Elements of Style* or the *AP Stylebook*. + +## Licensing + +Any code contributed to the project via patches, pull requests, or other means will be licensed under the [GPL version 2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) or later. By contributing code to the project, you provide consent to use such code under this license. The exception to this rule is when bringing in third-party code with an alternate open source license. + +## Versioning + +The project uses [semantic versioning](http://semver.org). Version numbers will look like `3.2.1` where `3` is the "major" release, `2` is the minor release, and `1` is the patch release. diff --git a/admin/butterbean/css/butterbean.css b/admin/butterbean/css/butterbean.css new file mode 100644 index 0000000..3d8f1ca --- /dev/null +++ b/admin/butterbean/css/butterbean.css @@ -0,0 +1,330 @@ + +/* Wrapper box */ + +.butterbean-ui { } + + .butterbean-ui > .hndle { + padding: 10px !important; + border-bottom: 1px solid #eee; + } + + .butterbean-ui .inside { + margin: 0 !important; + padding: 0; + } + +/* Tabs wrapper. */ + +.butterbean-manager-default { + overflow: hidden; + background: #fff; + background: linear-gradient( 90deg, #fafafa 0%, #fafafa 180px, #fff 180px, #fff 100% ); +} + + #side-sortables .butterbean-manager-default { + background: linear-gradient( 90deg, #fafafa 0%, #fafafa 48px, #fff 48px, #fff 100% ); + } + + @media only screen and ( max-width: 782px ), ( max-width: 980px ) and ( min-width: 851px ) { + + .butterbean-manager-default { + background: linear-gradient( 90deg, #fafafa 0%, #fafafa 48px, #fff 48px, #fff 100% ); + } + } + + /* Tab nav. */ + + .butterbean-manager-default .butterbean-nav { + position: relative; + float: left; + list-style: none; + width: 180px;/*20%;*/ + line-height: 1em; + margin: 0 0 -1px 0; + padding: 0; + background-color: #fafafa; + border-right: 1px solid #eee; + box-sizing: border-box; + } + + .butterbean-manager-default .butterbean-nav li { + display: block; + position: relative; + margin: 0; + padding: 0; + line-height: 20px; + } + + .butterbean-manager-default .butterbean-nav li a { + display: block; + margin: 0; + padding: 10px; + line-height: 20px !important; + text-decoration: none; + border-bottom: 1px solid #eee; + box-shadow: none; + } + + .butterbean-manager-default .butterbean-nav .dashicons { + line-height: 20px; + margin-right: 3px; + } + + .butterbean-manager-default .butterbean-nav li[aria-selected="true"] a { + position: relative; + font-weight: bold; + color: #555; + background-color: #e0e0e0; + } + + @media only screen and ( max-width: 782px ), ( max-width: 980px ) and ( min-width: 851px ) { + .butterbean-manager-default .butterbean-nav { width: 48px; } + + .butterbean-manager-default .butterbean-nav .dashicons { + width: 24px; + height: 24px; + font-size: 24px; + line-height: 24px; + } + + .butterbean-manager-default .butterbean-nav .dashicons::before { + width: 24px; + height: 24px; + } + + .butterbean-manager-default .butterbean-nav .label { + overflow: hidden; + position: absolute; + top: -1000em; + left: -1000em; + width: 1px; + height: 1px; + } + } + + /* Tab content wrapper */ + + .butterbean-manager-default .butterbean-content { + float: left; + width: calc( 100% - 180px ); + margin-left: -1px; + border-left: 1px solid #eee; + } + + @media only screen and ( max-width: 782px ), ( max-width: 980px ) and ( min-width: 851px ) { + + .butterbean-manager-default .butterbean-content { + width: calc( 100% - 48px ); + } + } + +/* === Manager when in the side meta box. === */ + +@media only screen and ( min-width: 850px ) { + + #side-sortables .butterbean-manager-default { background: #fff; } + + #side-sortables .butterbean-manager-default .butterbean-content { width: 100%; } + + #side-sortables .butterbean-manager-default .butterbean-nav { + display: table; + width: 100%; + } + + #side-sortables .butterbean-manager-default .butterbean-nav li { + display: table-cell; + text-align: center; + border-right: 1px solid #eee; + } + + #side-sortables .butterbean-manager-default .butterbean-nav li:last-of-type { border-right: none; } + + #side-sortables .butterbean-manager-default .butterbean-nav li a { + padding: 10px 0; + } + + #side-sortables .butterbean-manager-default .butterbean-nav .dashicons { + width: 24px; + height: 24px; + font-size: 24px; + line-height: 24px; + } + + #side-sortables .butterbean-manager-default .butterbean-nav .dashicons::before { + width: 24px; + height: 24px; + } + + #side-sortables .butterbean-manager-default .butterbean-nav .label { + overflow: hidden; + position: absolute; + top: -1000em; + left: -1000em; + width: 1px; + height: 1px; + } + } + + +/* === Content === */ + +.butterbean-manager-default .butterbean-section { + padding: 12px 12px 0; + box-sizing: border-box; +} + + .butterbean-manager-default .butterbean-section[aria-hidden="true"] { display: none; } + .butterbean-manager-default .butterbean-section[aria-hidden="false"] { display: block; } + +.butterbean-manager-default .butterbean-control { + margin-bottom: 20px; +} + + .butterbean-manager-default .butterbean-label { + display : block !important; /* this is getting overwritten somewhere */ + font-weight : bold; + display : inline-block; + margin-bottom : 4px; + } + + .butterbean-manager-default .butterbean-control-checkbox .butterbean-label { + display: inline !important; + } + + .butterbean-manager-default .butterbean-description { + display : block; + font-style : italic; + margin-top : 4px; + } + + .butterbean-manager-default .butterbean-label + .butterbean-description { + margin-top : 0; + margin-bottom : 4px; + } + +/* === Media === */ + +.butterbean-control-image .butterbean-img { + display: block; + max-width: 100%; + max-height: 300px; + height: auto; +} + +.butterbean-placeholder { + width: 100%; + position: relative; + text-align: center; + padding: 9px 0; + line-height: 20px; + border: 1px dashed rgb(180, 185, 190); + box-sizing: border-box; +} + +/* === Textarea Control === */ + +.butterbean-control-textarea textarea, +.butterbean-control-excerpt textarea { + display: block; + width: 100%; + height: 105px; +} + +/* === Date Control === */ + +.butterbean-control-datetime select { + vertical-align: top; +} + +/* === Palette Control === */ + +.butterbean-control-palette label { + display: block; + padding: 0 10px 10px; +} + +.butterbean-control-palette label[aria-selected="true"] { + padding-top: 5px; + background-color: #ddd; +} + + .butterbean-palette-label { + line-height: 28px; + } + + .butterbean-palette-block { + display: table; + width: 100%; + height: 45px; + border: 1px solid rgb(238, 238, 238); + box-sizing: border-box; + } + + .butterbean-palette-color { + display: table-cell; + height: 100%; + } + +/* === Radio Image Control === */ + +.butterbean-control-radio-image input[type="radio"] { + clip: rect(1px, 1px, 1px, 1px); + height: 1px; + overflow: hidden; + position: absolute !important; + width: 1px; +} + +.butterbean-control-radio-image img { + box-sizing: border-box; + max-width: 100%; + height: auto; + padding: 1px; + border: 4px solid transparent; +} + + .butterbean-control-radio-image img:hover, + .butterbean-control-radio-image img:focus { + border-color: #ccc; + } + + .butterbean-control-radio-image input:checked + span + img { + border-color: #00a0d2; + } + +/* === Multi-avatars Control === */ + +.butterbean-multi-avatars-wrap label { + display: inline-block; + margin-top: 8px; +} + + .butterbean-multi-avatars-wrap input[type="checkbox"] { + clip: rect( 1px, 1px, 1px, 1px ); + height: 1px; + overflow: hidden; + position: absolute !important; + width: 1px; + } + + .butterbean-multi-avatars-wrap .avatar { + box-sizing: border-box; + max-width: 100%; + height: auto; + padding: 1px; + border: 4px solid transparent; + } + + #side-sortables .butterbean-multi-avatars-wrap .avatar { + max-width: 60px; + max-height: 60px; + } + + .butterbean-multi-avatars-wrap img:hover, + .butterbean-multi-avatars-wrap img:focus { + border-color: #ccc; + } + + .butterbean-multi-avatars-wrap input:checked + span + img { + border-color: #00a0d2; + } diff --git a/admin/butterbean/css/butterbean.min.css b/admin/butterbean/css/butterbean.min.css new file mode 100644 index 0000000..14202c7 --- /dev/null +++ b/admin/butterbean/css/butterbean.min.css @@ -0,0 +1 @@ +.butterbean-ui>.hndle{padding:10px!important;border-bottom:1px solid #eee}.butterbean-ui .inside{margin:0!important;padding:0}.butterbean-manager-default{overflow:hidden;background:#fff;background:linear-gradient(90deg,#fafafa 0,#fafafa 180px,#fff 180px,#fff 100%)}#side-sortables .butterbean-manager-default{background:linear-gradient(90deg,#fafafa 0,#fafafa 48px,#fff 48px,#fff 100%)}@media only screen and (max-width:782px),(max-width:980px) and (min-width:851px){.butterbean-manager-default{background:linear-gradient(90deg,#fafafa 0,#fafafa 48px,#fff 48px,#fff 100%)}}.butterbean-manager-default .butterbean-nav{position:relative;float:left;list-style:none;width:180px;line-height:1em;margin:0 0 -1px 0;padding:0;background-color:#fafafa;border-right:1px solid #eee;box-sizing:border-box}.butterbean-manager-default .butterbean-nav li{display:block;position:relative;margin:0;padding:0;line-height:20px}.butterbean-manager-default .butterbean-nav li a{display:block;margin:0;padding:10px;line-height:20px!important;text-decoration:none;border-bottom:1px solid #eee;box-shadow:none}.butterbean-manager-default .butterbean-nav .dashicons{line-height:20px;margin-right:3px}.butterbean-manager-default .butterbean-nav li[aria-selected=true] a{position:relative;font-weight:700;color:#555;background-color:#e0e0e0}@media only screen and (max-width:782px),(max-width:980px) and (min-width:851px){.butterbean-manager-default .butterbean-nav{width:48px}.butterbean-manager-default .butterbean-nav .dashicons{width:24px;height:24px;font-size:24px;line-height:24px}.butterbean-manager-default .butterbean-nav .dashicons::before{width:24px;height:24px}.butterbean-manager-default .butterbean-nav .label{overflow:hidden;position:absolute;top:-1000em;left:-1000em;width:1px;height:1px}}.butterbean-manager-default .butterbean-content{float:left;width:calc(100% - 180px);margin-left:-1px;border-left:1px solid #eee}@media only screen and (max-width:782px),(max-width:980px) and (min-width:851px){.butterbean-manager-default .butterbean-content{width:calc(100% - 48px)}}@media only screen and (min-width:850px){#side-sortables .butterbean-manager-default{background:#fff}#side-sortables .butterbean-manager-default .butterbean-content{width:100%}#side-sortables .butterbean-manager-default .butterbean-nav{display:table;width:100%}#side-sortables .butterbean-manager-default .butterbean-nav li{display:table-cell;text-align:center;border-right:1px solid #eee}#side-sortables .butterbean-manager-default .butterbean-nav li:last-of-type{border-right:0}#side-sortables .butterbean-manager-default .butterbean-nav li a{padding:10px 0}#side-sortables .butterbean-manager-default .butterbean-nav .dashicons{width:24px;height:24px;font-size:24px;line-height:24px}#side-sortables .butterbean-manager-default .butterbean-nav .dashicons::before{width:24px;height:24px}#side-sortables .butterbean-manager-default .butterbean-nav .label{overflow:hidden;position:absolute;top:-1000em;left:-1000em;width:1px;height:1px}}.butterbean-manager-default .butterbean-section{padding:12px 12px 0;box-sizing:border-box}.butterbean-manager-default .butterbean-section[aria-hidden=true]{display:none}.butterbean-manager-default .butterbean-section[aria-hidden=false]{display:block}.butterbean-manager-default .butterbean-control{margin-bottom:20px}.butterbean-manager-default .butterbean-label{display:block!important;font-weight:700;display:inline-block;margin-bottom:4px}.butterbean-manager-default .butterbean-control-checkbox .butterbean-label{display:inline!important}.butterbean-manager-default .butterbean-description{display:block;font-style:italic;margin-top:4px}.butterbean-manager-default .butterbean-label+.butterbean-description{margin-top:0;margin-bottom:4px}.butterbean-control-image .butterbean-img{display:block;max-width:100%;max-height:300px;height:auto}.butterbean-placeholder{width:100%;position:relative;text-align:center;padding:9px 0;line-height:20px;border:1px dashed #b4b9be;box-sizing:border-box}.butterbean-control-textarea textarea,.butterbean-control-excerpt textarea{display:block;width:100%;height:105px}.butterbean-control-datetime select{vertical-align:top}.butterbean-control-palette label{display:block;padding:0 10px 10px}.butterbean-control-palette label[aria-selected=true]{padding-top:5px;background-color:#ddd}.butterbean-palette-label{line-height:28px}.butterbean-palette-block{display:table;width:100%;height:45px;border:1px solid #eee;box-sizing:border-box}.butterbean-palette-color{display:table-cell;height:100%}.butterbean-control-radio-image input[type=radio]{clip:rect(1px,1px,1px,1px);height:1px;overflow:hidden;position:absolute!important;width:1px}.butterbean-control-radio-image img{box-sizing:border-box;max-width:100%;height:auto;padding:1px;border:4px solid transparent}.butterbean-control-radio-image img:hover,.butterbean-control-radio-image img:focus{border-color:#ccc}.butterbean-control-radio-image input:checked+span+img{border-color:#00a0d2}.butterbean-multi-avatars-wrap label{display:inline-block;margin-top:8px}.butterbean-multi-avatars-wrap input[type=checkbox]{clip:rect(1px,1px,1px,1px);height:1px;overflow:hidden;position:absolute!important;width:1px}.butterbean-multi-avatars-wrap .avatar{box-sizing:border-box;max-width:100%;height:auto;padding:1px;border:4px solid transparent}#side-sortables .butterbean-multi-avatars-wrap .avatar{max-width:60px;max-height:60px}.butterbean-multi-avatars-wrap img:hover,.butterbean-multi-avatars-wrap img:focus{border-color:#ccc}.butterbean-multi-avatars-wrap input:checked+span+img{border-color:#00a0d2} \ No newline at end of file diff --git a/admin/butterbean/inc/class-control.php b/admin/butterbean/inc/class-control.php new file mode 100644 index 0000000..8b60507 --- /dev/null +++ b/admin/butterbean/inc/class-control.php @@ -0,0 +1,399 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Base control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control { + + /** + * Stores the manager object. + * + * @since 1.0.0 + * @access public + * @var object + */ + public $manager; + + /** + * Name/ID of the control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $name = ''; + + /** + * Label for the control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $label = ''; + + /** + * Description for the control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $description = ''; + + /** + * ID of the section the control is for. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $section = ''; + + /** + * The setting key for the specific setting the control is tied to. + * Controls can have multiple settings attached to them. The default + * setting is `default`. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $setting = 'default'; + + /** + * Array of settings if the control has multiple settings. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $settings = array(); + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'text'; + + /** + * Form field attributes. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $attr = ''; + + /** + * Choices for fields with multiple choices. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $choices = array(); + + /** + * Priority (order) the control should be output. + * + * @since 1.0.0 + * @access public + * @var int + */ + public $priority = 10; + + /** + * The number of instances created. + * + * @since 1.0.0 + * @access protected + * @var int + */ + protected static $instance_count = 0; + + /** + * The instance of the current control. + * + * @since 1.0.0 + * @access public + * @var int + */ + public $instance_number; + + /** + * A callback function for deciding if a control is active. + * + * @since 1.0.0 + * @access public + * @var callable + */ + public $active_callback = ''; + + /** + * A user role capability required to show the control. + * + * @since 1.0.0 + * @access public + * @var string|array + */ + public $capability = ''; + + /** + * A feature that the current post type must support to show the control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $post_type_supports = ''; + + /** + * A feature that the current theme must support to show the control. + * + * @since 1.0.0 + * @access public + * @var string|array + */ + public $theme_supports = ''; + + /** + * Stores the JSON data for the control. + * + * @since 1.0.0 + * @access public + * @var array() + */ + public $json = array(); + + /** + * Creates a new control object. + * + * @since 1.0.0 + * @access public + * @param object $manager + * @param string $name + * @param array $args + * @return void + */ + public function __construct( $manager, $name, $args = array() ) { + + foreach ( array_keys( get_object_vars( $this ) ) as $key ) { + + if ( isset( $args[ $key ] ) ) + $this->$key = $args[ $key ]; + } + + $this->manager = $manager; + $this->name = $name; + + if ( empty( $args['settings'] ) || ! is_array( $args['settings'] ) ) + $this->settings['default'] = $name; + + // Increment the instance count and set the instance number. + self::$instance_count += 1; + $this->instance_number = self::$instance_count; + + // Set the active callback function if not set. + if ( ! $this->active_callback ) + $this->active_callback = array( $this, 'active_callback' ); + } + + /** + * Enqueue scripts/styles for the control. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function enqueue() {} + + /** + * Get the value for the setting. + * + * @since 1.0.0 + * @access public + * @param string $setting + * @return mixed + */ + public function get_value( $setting = 'default' ) { + + $setting = $this->get_setting( $setting ); + + return $setting ? $setting->get_value() : ''; + } + + /** + * Returns the setting object associated with this control. If no setting is + * found, `false` is returned. + * + * @since 1.0.0 + * @access public + * @param string $setting + * @return object|bool + */ + public function get_setting( $setting = 'default' ) { + + return $this->manager->get_setting( $this->settings[ $setting ] ); + } + + /** + * Gets the attributes for the control. + * + * @since 1.0.0 + * @access public + * @return array + */ + public function get_attr() { + + $defaults = array(); + + if ( isset( $this->settings[ $this->setting ] ) ) + $defaults['name'] = $this->get_field_name( $this->setting ); + + return wp_parse_args( $this->attr, $defaults ); + } + + /** + * Returns the HTML field name for the control. + * + * @since 1.0.0 + * @access public + * @param string $setting + * @return array + */ + public function get_field_name( $setting = 'default' ) { + + return "butterbean_{$this->manager->name}_setting_{$this->settings[ $setting ]}"; + } + + /** + * Returns the json array. + * + * @since 1.0.0 + * @access public + * @return array + */ + public function get_json() { + $this->to_json(); + + return $this->json; + } + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + + $this->json['manager'] = $this->manager->name; + $this->json['section'] = $this->section; + $this->json['setting'] = $this->setting; + $this->json['settings'] = $this->settings; + $this->json['name'] = $this->name; + $this->json['label'] = $this->label; + $this->json['type'] = $this->type; + $this->json['description'] = $this->description; + $this->json['choices'] = $this->choices; + $this->json['active'] = $this->is_active(); + + $this->json['value'] = isset( $this->settings[ $this->setting ] ) ? $this->get_value( $this->setting ) : ''; + $this->json['field_name'] = isset( $this->settings[ $this->setting ] ) ? $this->get_field_name( $this->setting ) : ''; + + $this->json['attr'] = ''; + + foreach ( $this->get_attr() as $attr => $value ) { + $this->json['attr'] .= sprintf( '%s="%s" ', esc_html( $attr ), esc_attr( $value ) ); + } + } + + /** + * Returns whether the control is active. + * + * @since 1.0.0 + * @access public + * @return bool + */ + public function is_active() { + + $is_active = call_user_func( $this->active_callback, $this ); + + return apply_filters( 'butterbean_is_control_active', $is_active, $this ); + } + + /** + * Default active callback. + * + * @since 1.0.0 + * @access public + * @return bool + */ + public function active_callback() { + return true; + } + + /** + * Checks if the control should be allowed at all. + * + * @since 1.0.0 + * @access public + * @return bool + */ + public function check_capabilities() { + + if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) + return false; + + if ( $this->post_type_supports && ! call_user_func_array( 'post_type_supports', array( get_post_type( $this->manager->post_id ), $this->post_type_supports ) ) ) + return false; + + if ( $this->theme_supports && ! call_user_func_array( 'theme_supports', (array) $this->theme_supports ) ) + return false; + + return true; + } + + /** + * Prints Underscore.js template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function print_template() { ?> + + + type ); + } +} diff --git a/admin/butterbean/inc/class-manager.php b/admin/butterbean/inc/class-manager.php new file mode 100644 index 0000000..7116ddc --- /dev/null +++ b/admin/butterbean/inc/class-manager.php @@ -0,0 +1,550 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Base manager class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Manager { + + /** + * The type of manager. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'default'; + + /** + * Name of this instance of the manager. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $name = ''; + + /** + * Label for the manager. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $label = ''; + + /** + * Post type this manager is used on. + * + * @since 1.0.0 + * @access public + * @var string|array + */ + public $post_type = 'post'; + + /** + * Location of the meta box. Accepted values: 'normal', 'advanced', 'side'. + * + * @link https://developer.wordpress.org/reference/functions/add_meta_box/ + * @since 1.0.0 + * @access public + * @var string + */ + public $context = 'advanced'; + + /** + * Priority of the meta box. Accepted values: 'high', 'core', 'default', 'low'. + * + * @link https://developer.wordpress.org/reference/functions/add_meta_box/ + * @since 1.0.0 + * @access public + * @var string + */ + public $priority = 'default'; + + /** + * Array of sections. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $sections = array(); + + /** + * Array of controls. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $controls = array(); + + /** + * Array of settings. + * + * @since 1.0.0 + * @access public + * @var array + */ + public $settings = array(); + + /** + * A user role capability required to show the manager. + * + * @since 1.0.0 + * @access public + * @var string|array + */ + public $capability = ''; + + /** + * A feature that the current post type must support to show the manager. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $post_type_supports = ''; + + /** + * A feature that the current theme must support to show the manager. + * + * @since 1.0.0 + * @access public + * @var string|array + */ + public $theme_supports = ''; + + /** + * Stores the JSON data for the manager. + * + * @since 1.0.0 + * @access public + * @var array() + */ + public $json = array(); + + /** + * ID of the post that's being edited. + * + * @since 1.0.0 + * @access public + * @var int + */ + public $post_id = 0; + + /** + * Sets up the manager. + * + * @since 1.0.0 + * @access public + * @param string $name + * @param array $args + * @return void + */ + public function __construct( $name, $args = array() ) { + + foreach ( array_keys( get_object_vars( $this ) ) as $key ) { + + if ( isset( $args[ $key ] ) ) + $this->$key = $args[ $key ]; + } + + // Make sure the post type is an array. + $this->post_type = (array) $this->post_type; + + // Set the manager name. + $this->name = sanitize_key( $name ); + } + + /** + * Enqueue scripts/styles for the manager. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function enqueue() {} + + /** + * Register a section. + * + * @since 1.0.0 + * @access public + * @param object|string $section + * @param array $args + * @return void + */ + public function register_section( $section, $args = array() ) { + + if ( ! is_object( $section ) ) { + + $type = isset( $args['type'] ) ? butterbean()->get_section_type( $args['type'] ) : butterbean()->get_section_type( 'default' ); + + $section = new $type( $this, $section, $args ); + } + + if ( ! $this->section_exists( $section->name ) ) + $this->sections[ $section->name ] = $section; + } + + /** + * Register a control. + * + * @since 1.0.0 + * @access public + * @param object|string $control + * @param array $args + * @return void + */ + public function register_control( $control, $args = array() ) { + + if ( ! is_object( $control ) ) { + + $type = isset( $args['type'] ) ? butterbean()->get_control_type( $args['type'] ) : butterbean()->get_control_type( 'default' ); + + $control = new $type( $this, $control, $args ); + } + + if ( ! $this->control_exists( $control->name ) ) + $this->controls[ $control->name ] = $control; + } + + /** + * Register a setting. + * + * @since 1.0.0 + * @access public + * @param object|string $setting + * @param array $args + * @return void + */ + public function register_setting( $setting, $args = array() ) { + + if ( ! is_object( $setting ) ) { + + $type = isset( $args['type'] ) ? butterbean()->get_setting_type( $args['type'] ) : butterbean()->get_setting_type( 'default' ); + + $setting = new $type( $this, $setting, $args ); + } + + if ( ! $this->setting_exists( $setting->name ) ) + $this->settings[ $setting->name ] = $setting; + } + + /** + * Register a control and setting object. + * + * @since 1.0.0 + * @access public + * @param string $name + * @param object|array $control Control object or array of control arguments. + * @param object|array $setting Setting object or array of setting arguments. + * @return void + */ + public function register_field( $name, $control, $setting ) { + + is_object( $control ) ? $this->register_control( $control ) : $this->register_control( $name, $control ); + is_object( $setting ) ? $this->register_setting( $setting ) : $this->register_setting( $name, $setting ); + } + + /** + * Unregisters a section object. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return void + */ + public function unregister_section( $name ) { + + if ( $this->section_exists( $name ) ) + unset( $this->sections[ $name ] ); + } + + /** + * Unregisters a control object. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return void + */ + public function unregister_control( $name ) { + + if ( $this->control_exists( $name ) ) + unset( $this->controls[ $name ] ); + } + + /** + * Unregisters a setting object. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return void + */ + public function unregister_setting( $name ) { + + if ( $this->setting_exists( $name ) ) + unset( $this->settings[ $name ] ); + } + + /** + * Unregisters a control and setting object. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return void + */ + public function unregister_field( $name ) { + + $this->unregister_control( $name ); + $this->unregister_setting( $name ); + } + + /** + * Returns a section object. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return object|bool + */ + public function get_section( $name ) { + + return $this->section_exists( $name ) ? $this->sections[ $name ] : false; + } + + /** + * Returns a control object. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return object|bool + */ + public function get_control( $name ) { + + return $this->control_exists( $name ) ? $this->controls[ $name ] : false; + } + + /** + * Returns a setting object. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return object|bool + */ + public function get_setting( $name ) { + + return $this->setting_exists( $name ) ? $this->settings[ $name ] : false; + } + + /** + * Returns an object that contains both the control and setting objects. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return object|bool + */ + public function get_field( $name ) { + + $control = $this->get_control( $name ); + $setting = $this->get_setting( $name ); + + $field = array( 'name' => $name, 'control' => $control, 'setting' => $setting ); + + return $control && $setting ? (object) $field : false; + } + + /** + * Checks if a section exists. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return bool + */ + public function section_exists( $name ) { + + return isset( $this->sections[ $name ] ); + } + + /** + * Checks if a control exists. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return bool + */ + public function control_exists( $name ) { + + return isset( $this->controls[ $name ] ); + } + + /** + * Checks if a setting exists. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return bool + */ + public function setting_exists( $name ) { + + return isset( $this->settings[ $name ] ); + } + + /** + * Checks if a both a control and setting exist. + * + * @since 1.0.0 + * @access public + * @param string $name + * @return bool + */ + public function field_exists( $name ) { + + return $this->control_exists( $name ) && $this->setting_exists( $name ); + } + + /** + * Returns the json array. + * + * @since 1.0.0 + * @access public + * @return array + */ + public function get_json() { + $this->to_json(); + + return $this->json; + } + + /** + * Adds custom data to the JSON array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + + $sections_with_controls = array(); + $blocked_sections = array(); + + $this->json['name'] = $this->name; + $this->json['type'] = $this->type; + + // Get all sections that have controls. + foreach ( $this->controls as $control ) + $sections_with_controls[] = $control->section; + + $sections_with_controls = array_unique( $sections_with_controls ); + + // Get the JSON data for each section. + foreach ( $this->sections as $section ) { + + $caps = $section->check_capabilities(); + + if ( $caps && in_array( $section->name, $sections_with_controls ) ) + $this->json['sections'][] = $section->get_json(); + + if ( ! $caps ) + $blocked_sections[] = $section->name; + } + + // Get the JSON data for each control. + foreach ( $this->controls as $control ) { + + if ( $control->check_capabilities() && ! in_array( $control->section, $blocked_sections ) ) + $this->json['controls'][] = $control->get_json(); + } + } + + /** + * Saves each of the settings for the manager. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function save( $post_id ) { + + if ( ! $this->post_id ) + $this->post_id = $post_id; + + // Verify the nonce for this manager. + if ( ! isset( $_POST["butterbean_{$this->name}"] ) || ! wp_verify_nonce( $_POST["butterbean_{$this->name}"], "butterbean_{$this->name}_nonce" ) ) + return; + + // Loop through each setting and save it. + foreach ( $this->settings as $setting ) + $setting->save(); + } + + /** + * Checks if the control should be allowed at all. + * + * @since 1.0.0 + * @access public + * @return bool + */ + public function check_capabilities() { + + if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) + return false; + + if ( $this->post_type_supports && ! call_user_func_array( 'post_type_supports', array( get_post_type( $this->manager->post_id ), $this->post_type_supports ) ) ) + return false; + + if ( $this->theme_supports && ! call_user_func_array( 'theme_supports', (array) $this->theme_supports ) ) + return false; + + return true; + } + + /** + * Prints Underscore.js template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function print_template() { ?> + + + type ); + } +} diff --git a/admin/butterbean/inc/class-section.php b/admin/butterbean/inc/class-section.php new file mode 100644 index 0000000..550d425 --- /dev/null +++ b/admin/butterbean/inc/class-section.php @@ -0,0 +1,291 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Base section class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Section { + + /** + * Stores the project details manager object. + * + * @since 1.0.0 + * @access public + * @var object + */ + public $manager; + + /** + * Name/ID of the section. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $name = ''; + + /** + * The type of section. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'default'; + + /** + * Dashicons icon for the section. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $icon = 'dashicons-admin-generic'; + + /** + * Label for the section. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $label = ''; + + /** + * Description for the section. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $description = ''; + + /** + * Priority (order) the section should be output. + * + * @since 1.0.0 + * @access public + * @var int + */ + public $priority = 10; + + /** + * The number of instances created. + * + * @since 1.0.0 + * @access protected + * @var int + */ + protected static $instance_count = 0; + + /** + * The instance of the current section. + * + * @since 1.0.0 + * @access public + * @var int + */ + public $instance_number; + + /** + * A callback function for deciding if a section is active. + * + * @since 1.0.0 + * @access public + * @var callable + */ + public $active_callback = ''; + + /** + * A user role capability required to show the section. + * + * @since 1.0.0 + * @access public + * @var string|array + */ + public $capability = ''; + + /** + * A feature that the current post type must support to show the section. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $post_type_supports = ''; + + /** + * A feature that the current theme must support to show the section. + * + * @since 1.0.0 + * @access public + * @var string|array + */ + public $theme_supports = ''; + + /** + * Stores the JSON data for the manager. + * + * @since 1.0.0 + * @access public + * @var array() + */ + public $json = array(); + + /** + * Creates a new section object. + * + * @since 1.0.0 + * @access public + * @param object $manager + * @param string $section + * @param array $args + * @return void + */ + public function __construct( $manager, $name, $args = array() ) { + + foreach ( array_keys( get_object_vars( $this ) ) as $key ) { + + if ( isset( $args[ $key ] ) ) + $this->$key = $args[ $key ]; + } + + $this->manager = $manager; + $this->name = $name; + + // Increment the instance count and set the instance number. + self::$instance_count += 1; + $this->instance_number = self::$instance_count; + + // Set the active callback function if not set. + if ( ! $this->active_callback ) + $this->active_callback = array( $this, 'active_callback' ); + } + + /** + * Enqueue scripts/styles for the section. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function enqueue() {} + + /** + * Returns the json array. + * + * @since 1.0.0 + * @access public + * @return array + */ + public function get_json() { + $this->to_json(); + + return $this->json; + } + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + + $this->json['manager'] = $this->manager->name; + $this->json['name'] = $this->name; + $this->json['type'] = $this->type; + $this->json['icon'] = preg_match( '/dashicons-/', $this->icon ) ? sprintf( 'dashicons %s', sanitize_html_class( $this->icon ) ) : esc_attr( $this->icon ); + $this->json['label'] = $this->label; + $this->json['description'] = $this->description; + $this->json['active'] = $this->is_active(); + } + + /** + * Returns whether the section is active. + * + * @since 1.0.0 + * @access public + * @return bool + */ + public function is_active() { + + $is_active = call_user_func( $this->active_callback, $this ); + + if ( $is_active ) + $is_active = $this->check_capabilities(); + + return apply_filters( 'butterbean_is_section_active', $is_active, $this ); + } + + /** + * Default active callback. + * + * @since 1.0.0 + * @access public + * @return bool + */ + public function active_callback() { + return true; + } + + /** + * Checks if the section should be allowed at all. + * + * @since 1.0.0 + * @access public + * @return bool + */ + public function check_capabilities() { + + if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) + return false; + + if ( $this->post_type_supports && ! call_user_func_array( 'post_type_supports', array( get_post_type( $this->manager->post_id ), $this->post_type_supports ) ) ) + return false; + + if ( $this->theme_supports && ! call_user_func_array( 'theme_supports', (array) $this->theme_supports ) ) + return false; + + return true; + } + + /** + * Prints Underscore.js template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function print_template() { ?> + + + type ); + } +} diff --git a/admin/butterbean/inc/class-setting.php b/admin/butterbean/inc/class-setting.php new file mode 100644 index 0000000..d25e6eb --- /dev/null +++ b/admin/butterbean/inc/class-setting.php @@ -0,0 +1,226 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Base setting class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Setting { + + /** + * The type of setting. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'default'; + + /** + * Stores the manager object. + * + * @since 1.0.0 + * @access public + * @var object + */ + public $manager; + + /** + * Name/ID of the setting. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $name = ''; + + /** + * Value of the setting. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $value = ''; + + /** + * Default value of the setting. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $default = ''; + + /** + * Sanitization/Validation callback function. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $sanitize_callback = ''; + + /** + * A user role capability required to save the setting. + * + * @since 1.0.0 + * @access public + * @var string|array + */ + public $capability = ''; + + /** + * A feature that the current post type must support to save the setting. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $post_type_supports = ''; + + /** + * A feature that the current theme must support to save the setting. + * + * @since 1.0.0 + * @access public + * @var string|array + */ + public $theme_supports = ''; + + /** + * Creates a new setting object. + * + * @since 1.0.0 + * @access public + * @param object $manager + * @param string $cap + * @param array $args + * @return void + */ + public function __construct( $manager, $name, $args = array() ) { + + foreach ( array_keys( get_object_vars( $this ) ) as $key ) { + + if ( isset( $args[ $key ] ) ) + $this->$key = $args[ $key ]; + } + + $this->manager = $manager; + $this->name = $name; + + if ( $this->sanitize_callback ) + add_filter( "butterbean_{$this->manager->name}_sanitize_{$this->name}", $this->sanitize_callback, 10, 2 ); + } + + /** + * Gets the value of the setting. + * + * @since 1.0.0 + * @access public + * @return mixed + */ + public function get_value() { + + $value = get_post_meta( $this->manager->post_id, $this->name, true ); + + return ! $value && butterbean()->is_new_post ? $this->default : $value; + } + + /** + * Gets the posted value of the setting. + * + * @since 1.0.0 + * @access public + * @return mixed + */ + public function get_posted_value() { + + $value = ''; + + if ( isset( $_POST[ $this->get_field_name() ] ) ) + $value = $_POST[ $this->get_field_name() ]; + + return $this->sanitize( $value ); + } + + /** + * Retuns the correct field name for the setting. + * + * @since 1.0.0 + * @access public + * @return string + */ + public function get_field_name() { + + return "butterbean_{$this->manager->name}_setting_{$this->name}"; + } + + /** + * Sanitizes the value of the setting. + * + * @since 1.0.0 + * @access public + * @return mixed + */ + public function sanitize( $value ) { + + return apply_filters( "butterbean_{$this->manager->name}_sanitize_{$this->name}", $value, $this ); + } + + /** + * Saves the value of the setting. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function save() { + + if ( ! $this->check_capabilities() ) + return; + + $old_value = $this->get_value(); + $new_value = $this->get_posted_value(); + + // If we have don't have a new value but do have an old one, delete it. + if ( ! $new_value && $old_value ) + delete_post_meta( $this->manager->post_id, $this->name ); + + // If the new value doesn't match the old value, set it. + else if ( $new_value !== $old_value ) + update_post_meta( $this->manager->post_id, $this->name, $new_value ); + } + + /** + * Checks if the setting should be saved at all. + * + * @since 1.0.0 + * @access public + * @return bool + */ + public function check_capabilities() { + + if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) + return false; + + if ( $this->post_type_supports && ! call_user_func_array( 'post_type_supports', array( get_post_type( $this->manager->post_id ), $this->post_type_supports ) ) ) + return false; + + if ( $this->theme_supports && ! call_user_func_array( 'theme_supports', (array) $this->theme_supports ) ) + return false; + + return true; + } +} diff --git a/admin/butterbean/inc/controls/class-control-checkboxes.php b/admin/butterbean/inc/controls/class-control-checkboxes.php new file mode 100644 index 0000000..b905b30 --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-checkboxes.php @@ -0,0 +1,43 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Multiple checkboxes control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_CheckBoxes extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'checkboxes'; + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + parent::to_json(); + + $this->json['value'] = (array) $this->get_value(); + } +} diff --git a/admin/butterbean/inc/controls/class-control-color.php b/admin/butterbean/inc/controls/class-control-color.php new file mode 100644 index 0000000..bc40812 --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-color.php @@ -0,0 +1,104 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Color control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Color extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'color'; + + /** + * Custom options to pass to the color picker. Mostly, this is a wrapper for + * `iris()`, which is bundled with core WP. However, if they change pickers + * in the future, it may correspond to a different script. + * + * @link http://automattic.github.io/Iris/#options + * @link https://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/ + * @since 1.0.0 + * @access public + * @var array + */ + public $options = array(); + + /** + * Enqueue scripts/styles for the control. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function enqueue() { + + wp_enqueue_script( 'wp-color-picker' ); + wp_enqueue_style( 'wp-color-picker' ); + } + + /** + * Gets the attributes for the control. + * + * @since 1.0.0 + * @access public + * @return array + */ + public function get_attr() { + $attr = parent::get_attr(); + + $setting = $this->get_setting(); + + $attr['class'] = 'butterbean-color-picker'; + $attr['type'] = 'text'; + $attr['maxlength'] = 7; + $attr['data-default-color'] = $setting ? $setting->default : ''; + + return $attr; + } + + /** + * Get the value for the setting. + * + * @since 1.0.0 + * @access public + * @param string $setting + * @return mixed + */ + public function get_value( $setting = 'default' ) { + + $value = parent::get_value( $setting ); + + return ltrim( $value, '#' ); + } + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + parent::to_json(); + + $this->json['options'] = $this->options; + } +} diff --git a/admin/butterbean/inc/controls/class-control-date.php b/admin/butterbean/inc/controls/class-control-date.php new file mode 100644 index 0000000..997f335 --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-date.php @@ -0,0 +1,135 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Date control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Date extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'date'; + + /** + * Whether to show the time. Note that settings, particularly the + * `ButterBean_Setting_Date` class will store the time as `00:00:00` if + * no time is provided. + * + * @since 1.0.0 + * @access public + * @var bool + */ + public $show_time = true; + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @globl object $wp_locale + * @return void + */ + public function to_json() { + global $wp_locale; + + parent::to_json(); + + $this->json['show_time'] = $this->show_time; + + $field_name = $this->get_field_name(); + + // Get project start/end dates. + $date = $this->get_value(); + + // Get the year, month, and day. + $year = $date ? mysql2date( 'Y', $date, false ) : ''; + $month = $date ? mysql2date( 'm', $date, false ) : ''; + $day = $date ? mysql2date( 'd', $date, false ) : ''; + + // Get the hour, minute, and second. + $hour = $date ? mysql2date( 'H', $date, false ) : ''; + $minute = $date ? mysql2date( 'i', $date, false ) : ''; + $second = $date ? mysql2date( 's', $date, false ) : ''; + + // Year + $this->json['year'] = array( + 'value' => esc_attr( $year ), + 'label' => esc_html__( 'Year', 'butterbean' ), + 'name' => esc_attr( "{$field_name}_year" ), + 'attr' => sprintf( 'placeholder="%s" size="4" maxlength="4" autocomplete="off"', esc_attr( date_i18n( 'Y' ) ) ) + ); + + // Month + $this->json['month'] = array( + 'value' => esc_attr( $month ), + 'name' => esc_attr( "{$field_name}_month" ), + 'label' => esc_html__( 'Month', 'butterbean' ), + 'choices' => array( + array( + 'num' => '', + 'label' => '' + ) + ) + ); + + for ( $i = 1; $i < 13; $i = $i +1 ) { + + $monthnum = zeroise( $i, 2 ); + $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ); + + $this->json['month']['choices'][] = array( + 'num' => $monthnum, + 'label' => $monthtext + ); + } + + // Day + $this->json['day'] = array( + 'value' => esc_attr( $day ), + 'name' => esc_attr( "{$field_name}_day" ), + 'label' => esc_html__( 'Day', 'butterbean' ), + 'attr' => sprintf( 'placeholder="%s" size="2" maxlength="2" autocomplete="off"', esc_attr( date_i18n( 'd' ) ) ) + ); + + // Hour + $this->json['hour'] = array( + 'value' => esc_attr( $hour ), + 'name' => esc_attr( "{$field_name}_hour" ), + 'label' => esc_html__( 'Hour', 'butterbean' ), + 'attr' => 'placeholder="00" size="2" maxlength="2" autocomplete="off"' + ); + + // Minute + $this->json['minute'] = array( + 'value' => esc_attr( $minute ), + 'name' => esc_attr( "{$field_name}_minute" ), + 'label' => esc_html__( 'Minute', 'butterbean' ), + 'attr' => 'placeholder="00" size="2" maxlength="2" autocomplete="off"' + ); + + // Second + $this->json['second'] = array( + 'value' => esc_attr( $second ), + 'name' => esc_attr( "{$field_name}_second" ), + 'label' => esc_html__( 'Second', 'butterbean' ), + 'attr' => 'placeholder="00" size="2" maxlength="2" autocomplete="off"' + ); + } +} diff --git a/admin/butterbean/inc/controls/class-control-datetime.php b/admin/butterbean/inc/controls/class-control-datetime.php new file mode 100644 index 0000000..b6e883c --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-datetime.php @@ -0,0 +1,140 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Datetime control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Datetime extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'datetime'; + + /** + * Whether to show the time. Note that settings, particularly the + * `ButterBean_Setting_Date` class will store the time as `00:00:00` if + * no time is provided. + * + * @since 1.0.0 + * @access public + * @var bool + */ + public $show_time = true; + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @globl object $wp_locale + * @return void + */ + public function to_json() { + global $wp_locale; + + parent::to_json(); + + $this->json['show_time'] = $this->show_time; + + $field_name = $this->get_field_name(); + + // Get project start/end dates. + $date = $this->get_value(); + + // Get the year, month, and day. + $year = $date ? mysql2date( 'Y', $date, false ) : ''; + $month = $date ? mysql2date( 'm', $date, false ) : ''; + $day = $date ? mysql2date( 'd', $date, false ) : ''; + + // Get the hour, minute, and second. + $hour = $date ? mysql2date( 'H', $date, false ) : ''; + $minute = $date ? mysql2date( 'i', $date, false ) : ''; + $second = $date ? mysql2date( 's', $date, false ) : ''; + + // Year + $this->json['year'] = array( + 'value' => esc_attr( $year ), + 'label' => esc_html__( 'Year', 'butterbean' ), + 'name' => esc_attr( "{$field_name}_year" ), + 'attr' => sprintf( 'placeholder="%s" size="4" maxlength="4" autocomplete="off"', esc_attr( date_i18n( 'Y' ) ) ) + ); + + // Month + $this->json['month'] = array( + 'value' => esc_attr( $month ), + 'name' => esc_attr( "{$field_name}_month" ), + 'label' => esc_html__( 'Month', 'butterbean' ), + 'choices' => array( + array( + 'num' => '', + 'label' => '' + ) + ) + ); + + for ( $i = 1; $i < 13; $i = $i +1 ) { + + $monthnum = zeroise( $i, 2 ); + $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ); + + $this->json['month']['choices'][] = array( + 'num' => $monthnum, + 'label' => $monthtext + ); + } + + // Day + $this->json['day'] = array( + 'value' => esc_attr( $day ), + 'name' => esc_attr( "{$field_name}_day" ), + 'label' => esc_html__( 'Day', 'butterbean' ), + 'attr' => sprintf( 'placeholder="%s" size="2" maxlength="2" autocomplete="off"', esc_attr( date_i18n( 'd' ) ) ) + ); + + // Hour + $this->json['hour'] = array( + 'value' => esc_attr( $hour ), + 'name' => esc_attr( "{$field_name}_hour" ), + 'label' => esc_html__( 'Hour', 'butterbean' ), + 'attr' => 'placeholder="00" size="2" maxlength="2" autocomplete="off"' + ); + + // Minute + $this->json['minute'] = array( + 'value' => esc_attr( $minute ), + 'name' => esc_attr( "{$field_name}_minute" ), + 'label' => esc_html__( 'Minute', 'butterbean' ), + 'attr' => 'placeholder="00" size="2" maxlength="2" autocomplete="off"' + ); + + // Second + $this->json['second'] = array( + 'value' => esc_attr( $second ), + 'name' => esc_attr( "{$field_name}_second" ), + 'label' => esc_html__( 'Second', 'butterbean' ), + 'attr' => 'placeholder="00" size="2" maxlength="2" autocomplete="off"' + ); + } +} diff --git a/admin/butterbean/inc/controls/class-control-excerpt.php b/admin/butterbean/inc/controls/class-control-excerpt.php new file mode 100644 index 0000000..c99b61a --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-excerpt.php @@ -0,0 +1,82 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Excerpt control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Excerpt extends ButterBean_Control_Textarea { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'excerpt'; + + /** + * Gets the attributes for the control. + * + * @since 1.0.0 + * @access public + * @return array + */ + public function get_attr() { + $attr = parent::get_attr(); + + $attr['id'] = 'post_excerpt'; + + return $attr; + } + + /** + * Returns the HTML field name for the control. + * + * @since 1.0.0 + * @access public + * @param string $setting + * @return string + */ + public function get_field_name( $setting = 'default' ) { + return 'post_excerpt'; + } + + /** + * Get the value for the setting. + * + * @since 1.0.0 + * @access public + * @param string $setting + * @return mixed + */ + public function get_value( $setting = 'default' ) { + + return get_post( $this->manager->post_id )->post_excerpt; + } + + /** + * Gets the Underscore.js template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function get_template() { + butterbean_get_control_template( 'textarea' ); + } +} diff --git a/admin/butterbean/inc/controls/class-control-image.php b/admin/butterbean/inc/controls/class-control-image.php new file mode 100644 index 0000000..7411069 --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-image.php @@ -0,0 +1,112 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Image control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Image extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'image'; + + /** + * Array of text labels to use for the media upload frame. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $l10n = array(); + + /** + * Image size to display. If the size isn't found for the image, + * the full size of the image will be output. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $size = 'large'; + + /** + * Creates a new control object. + * + * @since 1.0.0 + * @access public + * @param object $manager + * @param string $name + * @param array $args + * @return void + */ + public function __construct( $manager, $name, $args = array() ) { + parent::__construct( $manager, $name, $args ); + + $this->l10n = wp_parse_args( + $this->l10n, + array( + 'upload' => esc_html__( 'Add image', 'butterbean' ), + 'set' => esc_html__( 'Set as image', 'butterbean' ), + 'choose' => esc_html__( 'Choose image', 'butterbean' ), + 'change' => esc_html__( 'Change image', 'butterbean' ), + 'remove' => esc_html__( 'Remove image', 'butterbean' ), + 'placeholder' => esc_html__( 'No image selected', 'butterbean' ) + ) + ); + } + + /** + * Enqueue scripts/styles for the control. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function enqueue() { + + wp_enqueue_script( 'media-views' ); + } + + /** + * Adds custom data to the json array. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + parent::to_json(); + + $this->json['l10n'] = $this->l10n; + $this->json['size'] = $this->size; + + $value = $this->get_value(); + $image = $alt = ''; + + if ( $value ) { + $image = wp_get_attachment_image_src( absint( $value ), $this->size ); + $alt = get_post_meta( absint( $value ), '_wp_attachment_image_alt', true ); + } + + $this->json['src'] = $image ? esc_url( $image[0] ) : ''; + $this->json['alt'] = $alt ? esc_attr( $alt ) : ''; + } +} diff --git a/admin/butterbean/inc/controls/class-control-multi-avatars.php b/admin/butterbean/inc/controls/class-control-multi-avatars.php new file mode 100644 index 0000000..00b9c0b --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-multi-avatars.php @@ -0,0 +1,90 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Multi-avatars control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Multi_Avatars extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'multi-avatars'; + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + parent::to_json(); + + $this->json['value'] = is_array( $this->get_value() ) ? array_map( 'absint', $this->get_value() ) : array(); + $this->json['choices'] = array(); + + $users = get_users( array( 'role__in' => $this->get_roles() ) ); + + foreach ( $users as $user ) { + $this->json['choices'][] = array( + 'id' => $user->ID, + 'name' => $user->display_name, + 'avatar' => get_avatar( $user->ID, 70 ) + ); + } + } + + /** + * Returns an array of user roles that are allowed to edit, publish, or create + * posts of the given post type. + * + * @since 1.0.0 + * @access public + * @global object $wp_roles + * @return array + */ + public function get_roles() { + global $wp_roles; + + $roles = array(); + $type = get_post_type_object( get_post_type( $this->manager->post_id ) ); + + // Get the post type object caps. + $caps = array( $type->cap->edit_posts, $type->cap->publish_posts, $type->cap->create_posts ); + $caps = array_unique( $caps ); + + // Loop through the available roles. + foreach ( $wp_roles->roles as $name => $role ) { + + foreach ( $caps as $cap ) { + + // If the role is granted the cap, add it. + if ( isset( $role['capabilities'][ $cap ] ) && true === $role['capabilities'][ $cap ] ) { + $roles[] = $name; + break; + } + } + } + + return $roles; + } +} diff --git a/admin/butterbean/inc/controls/class-control-palette.php b/admin/butterbean/inc/controls/class-control-palette.php new file mode 100644 index 0000000..6e4bc30 --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-palette.php @@ -0,0 +1,51 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Color palette control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Palette extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'palette'; + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + parent::to_json(); + + $value = $this->get_value(); + + // Make sure the colors have a hash. + foreach ( $this->choices as $choice => $palette ) { + $this->choices[ $choice ]['colors'] = array_map( 'butterbean_maybe_hash_hex_color', $palette['colors'] ); + + $this->choices[ $choice ]['selected'] = $value && $choice === $value; + } + + $this->json['choices'] = $this->choices; + } +} diff --git a/admin/butterbean/inc/controls/class-control-parent.php b/admin/butterbean/inc/controls/class-control-parent.php new file mode 100644 index 0000000..f173d5d --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-parent.php @@ -0,0 +1,97 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Post parent control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Parent extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'parent'; + + /** + * The post type to select posts from. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $post_type = ''; + + /** + * Returns the HTML field name for the control. + * + * @since 1.0.0 + * @access public + * @param string $setting + * @return array + */ + public function get_field_name( $setting = 'default' ) { + + return 'post_parent'; + } + + /** + * Get the value for the setting. + * + * @since 1.0.0 + * @access public + * @param string $setting + * @return mixed + */ + public function get_value( $setting = 'default' ) { + + return get_post( $this->manager->post_id )->post_parent; + } + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + parent::to_json(); + + $_post = get_post( $this->manager->post_id ); + + $posts = get_posts( + array( + 'post_type' => $this->post_type ? $this->post_type : get_post_type( $this->manager->post_id ), + 'post_status' => 'any', + 'post__not_in' => array( $this->manager->post_id ), + 'posts_per_page' => -1, + 'post_parent' => 0, + 'orderby' => 'title', + 'order' => 'ASC', + 'fields' => array( 'ID', 'post_title' ) + ) + ); + + $this->json['choices'] = array( array( 'value' => 0, 'label' => '' ) ); + + foreach ( $posts as $post ) + $this->json['choices'][] = array( 'value' => $post->ID, 'label' => $post->post_title ); + } +} diff --git a/admin/butterbean/inc/controls/class-control-radio-image.php b/admin/butterbean/inc/controls/class-control-radio-image.php new file mode 100644 index 0000000..d8d2001 --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-radio-image.php @@ -0,0 +1,46 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Radio image control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Radio_Image extends ButterBean_Control_Radio { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'radio-image'; + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + parent::to_json(); + + foreach ( $this->choices as $value => $args ) + $this->choices[ $value ]['url'] = esc_url( sprintf( $args['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ) ); + + $this->json['choices'] = $this->choices; + } +} diff --git a/admin/butterbean/inc/controls/class-control-radio.php b/admin/butterbean/inc/controls/class-control-radio.php new file mode 100644 index 0000000..c6d2576 --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-radio.php @@ -0,0 +1,46 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Radio control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Radio extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'radio'; + + /** + * Radio controls imply that a value should be set. Therefore, we will return + * the default if there is no value. + * + * @since 1.0.0 + * @access public + * @param string $setting + * @return mixed + */ + public function get_value( $setting = 'default' ) { + + $value = parent::get_value( $setting ); + $object = $this->get_setting( $setting ); + + return ! $value && $object ? $object->default : $value; + } +} diff --git a/admin/butterbean/inc/controls/class-control-select-group.php b/admin/butterbean/inc/controls/class-control-select-group.php new file mode 100644 index 0000000..1dc427d --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-select-group.php @@ -0,0 +1,53 @@ +` to be added. + * + * @package ButterBean + * @author Justin Tadlock + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Select group control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Select_Group extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'select-group'; + + /** + * Adds custom data to the json array. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + parent::to_json(); + + $choices = $group = array(); + + foreach ( $this->choices as $choice => $maybe_group ) { + + if ( is_array( $maybe_group ) ) + $group[ $choice ] = $maybe_group; + else + $choices[ $choice ] = $maybe_group; + } + + $this->json['choices'] = $choices; + $this->json['group'] = $group; + } +} diff --git a/admin/butterbean/inc/controls/class-control-textarea.php b/admin/butterbean/inc/controls/class-control-textarea.php new file mode 100644 index 0000000..9b6e7c5 --- /dev/null +++ b/admin/butterbean/inc/controls/class-control-textarea.php @@ -0,0 +1,42 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Textarea control class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Control_Textarea extends ButterBean_Control { + + /** + * The type of control. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'textarea'; + + /** + * Adds custom data to the json array. This data is passed to the Underscore template. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function to_json() { + parent::to_json(); + + $this->json['value'] = esc_textarea( $this->get_value() ); + } +} diff --git a/admin/butterbean/inc/functions-core.php b/admin/butterbean/inc/functions-core.php new file mode 100644 index 0000000..cec10c5 --- /dev/null +++ b/admin/butterbean/inc/functions-core.php @@ -0,0 +1,169 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Function for validating booleans before saving them as metadata. If the value is + * `true`, we'll return a `1` to be stored as the meta value. Else, we return `false`. + * + * @since 1.0.0 + * @access public + * @param mixed + * @return bool|int + */ +function butterbean_validate_boolean( $value ) { + + return wp_validate_boolean( $value ) ? 1 : false; +} + +/** + * Pre-WP 4.6 function for sanitizing hex colors. + * + * @since 1.0.0 + * @access public + * @param string $color + * @return string + */ +function butterbean_sanitize_hex_color( $color ) { + + if ( function_exists( 'sanitize_hex_color' ) ) + return sanitize_hex_color( $color ); + + return $color && preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ? $color : ''; +} + +/** + * Pre-WP 4.6 function for sanitizing hex colors without a hash. + * + * @since 1.0.0 + * @access public + * @param string $color + * @return string + */ +function butterbean_sanitize_hex_color_no_hash( $color ) { + + if ( function_exists( 'sanitize_hex_color_no_hash' ) ) + return sanitize_hex_color_no_hash( $color ); + + $color = ltrim( $color, '#' ); + + if ( '' === $color ) + return ''; + + return butterbean_sanitize_hex_color( '#' . $color ) ? $color : null; +} + +/** + * Pre-WP 4.6 function for sanitizing a color and adding a hash. + * + * @since 1.0.0 + * @access public + * @param string $color + * @return string + */ +function butterbean_maybe_hash_hex_color( $color ) { + + if ( function_exists( 'maybe_hash_hex_color' ) ) + return maybe_hash_hex_color( $color ); + + if ( $unhashed = butterbean_sanitize_hex_color_no_hash( $color ) ) + return '#' . $unhashed; + + return $color; +} + +/** + * Gets Underscore.js templates for managers. + * + * @since 1.0.0 + * @param string $slug + * @return void + */ +function butterbean_get_manager_template( $slug = '' ) { + butterbean_get_template( 'manager', $slug ); +} + +/** + * Gets Underscore.js templates for navs. + * + * @since 1.0.0 + * @param string $slug + * @return void + */ +function butterbean_get_nav_template( $slug = '' ) { + butterbean_get_template( 'nav', $slug ); +} + +/** + * Gets Underscore.js templates for sections. + * + * @since 1.0.0 + * @param string $slug + * @return void + */ +function butterbean_get_section_template( $slug = '' ) { + butterbean_get_template( 'section', $slug ); +} + +/** + * Gets Underscore.js templates for controls. + * + * @since 1.0.0 + * @param string $slug + * @return void + */ +function butterbean_get_control_template( $slug = '' ) { + butterbean_get_template( 'control', $slug ); +} + +/** + * Helper function for getting Underscore.js templates. + * + * @since 1.0.0 + * @param string $name + * @param string $slug + * @return void + */ +function butterbean_get_template( $name, $slug = '' ) { + + // Allow devs to hook in early to bypass template checking. + $located = apply_filters( "butterbean_pre_{$name}_template", '', $slug ); + + // If there's no template, let's try to find one. + if ( ! $located ) { + + $templates = array(); + + if ( $slug ) + $templates[] = "{$name}-{$slug}.php"; + + $templates[] = "{$name}.php"; + + // Allow devs to filter the template hierarchy. + $templates = apply_filters( "butterbean_{$name}_template_hierarchy", $templates, $slug ); + + // Loop through the templates and locate one. + foreach ( $templates as $template ) { + + if ( file_exists( butterbean()->tmpl_path . $template ) ) { + $located = butterbean()->tmpl_path . $template; + break; + } + } + } + + // Allow devs to filter the final template. + $located = apply_filters( "butterbean_{$name}_template", $located, $slug ); + + // Load the template. + if ( $located ) + require( $located ); +} diff --git a/admin/butterbean/inc/settings/class-setting-array.php b/admin/butterbean/inc/settings/class-setting-array.php new file mode 100644 index 0000000..6d39543 --- /dev/null +++ b/admin/butterbean/inc/settings/class-setting-array.php @@ -0,0 +1,80 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Array setting class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Setting_Array extends ButterBean_Setting { + + /** + * The type of setting. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'array'; + + /** + * Sanitizes the value of the setting. + * + * @since 1.0.0 + * @access public + * @param array $value + * @return array + */ + public function sanitize( $values ) { + + $multi_values = $values && ! is_array( $values ) ? explode( ',', $values ) : $values; + + return $multi_values ? array_map( array( $this, 'map' ), $multi_values ) : array(); + } + + /** + * Helper function for sanitizing each value of the array. + * + * @since 1.0.0 + * @access public + * @param mixed $value + * @return mixed + */ + public function map( $value ) { + + return apply_filters( "butterbean_{$this->manager->name}_sanitize_{$this->name}", $value, $this ); + } + + /** + * Saves the value of the setting. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function save() { + + if ( ! $this->check_capabilities() ) + return; + + $old_values = $this->get_value(); + $new_values = $this->get_posted_value(); + + // If there's an array of posted values, set them. + if ( $new_values && is_array( $new_values ) && $new_values !== $old_values ) + return update_post_meta( $this->manager->post_id, $this->name, $new_values ); + + // If no array of posted values but we have old values, delete them. + else if ( $old_values && ! $new_values ) + return delete_post_meta( $this->manager->post_id, $this->name ); + } +} diff --git a/admin/butterbean/inc/settings/class-setting-date.php b/admin/butterbean/inc/settings/class-setting-date.php new file mode 100644 index 0000000..2563bd0 --- /dev/null +++ b/admin/butterbean/inc/settings/class-setting-date.php @@ -0,0 +1,105 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Date setting class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Setting_Date extends ButterBean_Setting { + + /** + * The type of setting. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'date'; + + /** + * Gets the posted value of the setting. + * + * @since 1.0.0 + * @access public + * @return mixed + */ + public function get_posted_value() { + + $field_name = $this->get_field_name(); + + // Get the posted date. + $year = ! empty( $_POST[ "{$field_name}_year" ] ) ? zeroise( absint( $_POST[ "{$field_name}_year" ] ), 4 ) : ''; + $month = ! empty( $_POST[ "{$field_name}_month" ] ) ? zeroise( absint( $_POST[ "{$field_name}_month" ] ), 2 ) : ''; + $day = ! empty( $_POST[ "{$field_name}_day" ] ) ? zeroise( absint( $_POST[ "{$field_name}_day" ] ), 2 ) : ''; + + // Get the posted time. + $hour = ! empty( $_POST[ "{$field_name}_hour" ] ) ? $this->validate_hour( $_POST[ "{$field_name}_hour" ] ) : '00'; + $minute = ! empty( $_POST[ "{$field_name}_minute" ] ) ? $this->validate_minute( $_POST[ "{$field_name}_minute" ] ) : '00'; + $second = ! empty( $_POST[ "{$field_name}_second" ] ) ? $this->validate_second( $_POST[ "{$field_name}_second" ] ) : '00'; + + $date = "{$year}-{$month}-{$day}"; + $time = "{$hour}:{$minute}:{$second}"; + + if ( $year && $month && $day && wp_checkdate( absint( $month ), absint( $day ), absint( $year ), $date ) ) + return "{$date} {$time}"; + + return ''; + } + + /** + * Validates the hour. + * + * @since 1.0.0 + * @access public + * @param int|string $hour + * @return string + */ + public function validate_hour( $hour ) { + + $hour = absint( $hour ); + + return $hour < 0 || $hour > 23 ? zeroise( $hour, 2 ) : '00'; + } + + /** + * Validates the minute. + * + * @since 1.0.0 + * @access public + * @param int|string $minute + * @return string + */ + public function validate_minute( $minute ) { + + $minute = absint( $minute ); + + return $minute < 0 || $minute > 59 ? zeroise( $minute, 2 ) : '00'; + } + + /** + * Validates the second. + * + * @since 1.0.0 + * @access public + * @param int|string $second + * @return string + */ + public function validate_second( $second ) { + + $second = absint( $second ); + + return $second < 0 || $second > 59 ? zeroise( $second, 2 ) : '00'; + } +} diff --git a/admin/butterbean/inc/settings/class-setting-datetime.php b/admin/butterbean/inc/settings/class-setting-datetime.php new file mode 100644 index 0000000..a22465b --- /dev/null +++ b/admin/butterbean/inc/settings/class-setting-datetime.php @@ -0,0 +1,105 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Date setting class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Setting_Datetime extends ButterBean_Setting { + + /** + * The type of setting. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'datetime'; + + /** + * Gets the posted value of the setting. + * + * @since 1.0.0 + * @access public + * @return mixed + */ + public function get_posted_value() { + + $field_name = $this->get_field_name(); + + // Get the posted date. + $year = ! empty( $_POST[ "{$field_name}_year" ] ) ? zeroise( absint( $_POST[ "{$field_name}_year" ] ), 4 ) : ''; + $month = ! empty( $_POST[ "{$field_name}_month" ] ) ? zeroise( absint( $_POST[ "{$field_name}_month" ] ), 2 ) : ''; + $day = ! empty( $_POST[ "{$field_name}_day" ] ) ? zeroise( absint( $_POST[ "{$field_name}_day" ] ), 2 ) : ''; + + // Get the posted time. + $hour = ! empty( $_POST[ "{$field_name}_hour" ] ) ? $this->validate_hour( $_POST[ "{$field_name}_hour" ] ) : '00'; + $minute = ! empty( $_POST[ "{$field_name}_minute" ] ) ? $this->validate_minute( $_POST[ "{$field_name}_minute" ] ) : '00'; + $second = ! empty( $_POST[ "{$field_name}_second" ] ) ? $this->validate_second( $_POST[ "{$field_name}_second" ] ) : '00'; + + $date = "{$year}-{$month}-{$day}"; + $time = "{$hour}:{$minute}:{$second}"; + + if ( $year && $month && $day && wp_checkdate( absint( $month ), absint( $day ), absint( $year ), $date ) ) + return "{$date} {$time}"; + + return ''; + } + + /** + * Validates the hour. + * + * @since 1.0.0 + * @access public + * @param int|string $hour + * @return string + */ + public function validate_hour( $hour ) { + + $hour = absint( $hour ); + + return $hour < 0 || $hour > 23 ? zeroise( $hour, 2 ) : '00'; + } + + /** + * Validates the minute. + * + * @since 1.0.0 + * @access public + * @param int|string $minute + * @return string + */ + public function validate_minute( $minute ) { + + $minute = absint( $minute ); + + return $minute < 0 || $minute > 59 ? zeroise( $minute, 2 ) : '00'; + } + + /** + * Validates the second. + * + * @since 1.0.0 + * @access public + * @param int|string $second + * @return string + */ + public function validate_second( $second ) { + + $second = absint( $second ); + + return $second < 0 || $second > 59 ? zeroise( $second, 2 ) : '00'; + } +} diff --git a/admin/butterbean/inc/settings/class-setting-multiple.php b/admin/butterbean/inc/settings/class-setting-multiple.php new file mode 100644 index 0000000..e4b1f39 --- /dev/null +++ b/admin/butterbean/inc/settings/class-setting-multiple.php @@ -0,0 +1,154 @@ + + * @copyright Copyright (c) 2015-2016, Justin Tadlock + * @link https://github.com/justintadlock/butterbean + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + */ + +/** + * Multiple setting class. + * + * @since 1.0.0 + * @access public + */ +class ButterBean_Setting_Multiple extends ButterBean_Setting { + + /** + * The type of setting. + * + * @since 1.0.0 + * @access public + * @var string + */ + public $type = 'multiple'; + + /** + * Gets the value of the setting. + * + * @since 1.0.0 + * @access public + * @return mixed + */ + public function get_value() { + + return get_post_meta( $this->manager->post_id, $this->name ); + } + + /** + * Sanitizes the value of the setting. + * + * @since 1.0.0 + * @access public + * @param array $value + * @return array + */ + public function sanitize( $values ) { + + $multi_values = $values && ! is_array( $values ) ? explode( ',', $values ) : $values; + + return $multi_values ? array_map( array( $this, 'map' ), $multi_values ) : array(); + } + + /** + * Helper function for sanitizing each value of the array. + * + * @since 1.0.0 + * @access public + * @param mixed $value + * @return mixed + */ + public function map( $value ) { + + return apply_filters( "butterbean_{$this->manager->name}_sanitize_{$this->name}", $value, $this ); + } + + /** + * Saves the value of the setting. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function save() { + + if ( ! $this->check_capabilities() ) + return; + + $old_values = $this->get_value(); + $new_values = $this->get_posted_value(); + + // If there's an array of posted values, set them. + if ( is_array( $new_values ) ) + $this->set_values( $new_values, $old_values ); + + // If no array of posted values but we have old values, delete them. + else if ( $old_values ) + $this->delete_values(); + } + + /** + * Loops through new and old meta values and updates. + * + * @since 1.0.0 + * @access public + * @param array $new_values + * @param array $old_values + * @return void + */ + public function set_values( $new_values, $old_values ) { + + foreach ( $new_values as $new ) { + + if ( ! in_array( $new, $old_values ) ) + $this->add_value( $new ); + } + + foreach ( $old_values as $old ) { + + if ( ! in_array( $old, $new_values ) ) + $this->remove_value( $old ); + } + } + + /** + * Deletes old meta values. + * + * @since 1.0.0 + * @access public + * @return void + */ + public function delete_values() { + + return delete_post_meta( $this->manager->post_id, $this->name ); + } + + /** + * Adds a single meta value. + * + * @since 1.0.0 + * @access public + * @param mixed $value + * @return bool + */ + public function add_value( $value ) { + + return add_post_meta( $this->manager->post_id, $this->name, $value, false ); + } + + /** + * Deletes a single meta value. + * + * @since 1.0.0 + * @access public + * @param mixed $value + * @return bool + */ + public function remove_value( $value ) { + + return delete_post_meta( $this->manager->post_id, $this->name, $value ); + } +} diff --git a/admin/butterbean/js/butterbean.js b/admin/butterbean/js/butterbean.js new file mode 100644 index 0000000..b85cb0b --- /dev/null +++ b/admin/butterbean/js/butterbean.js @@ -0,0 +1,875 @@ +window.butterbean = window.butterbean || {}; + +( function() { + + // Bail if we don't have the JSON, which is passed in via `wp_localize_script()`. + if ( _.isUndefined( butterbean_data ) ) { + return; + } + + /** + * Our global object. The `butterbean` object is just a wrapper to house everything + * in a single namespace. + * + * @since 1.0.0 + * @access public + * @var object + */ + var api = butterbean = { + + /** + * Houses the manager, section, and control views based on the `type`. + * + * @since 1.0.0 + * @access public + * @var object + */ + views : { managers : {}, sections : {}, controls : {} }, + + /** + * Houses the manager, section, and control templates based on the `type`. + * + * @since 1.0.0 + * @access public + * @var object + */ + templates : { managers : {}, sections : {}, controls : {} } + }; + + /** + * Creates a new manager view. + * + * @since 1.0.0 + * @access public + * @param string $type + * @param object $args + * @return void + */ + api.views.register_manager = function( type, args ) { + + if ( 'default' !== type ) + this.managers[ type ] = this.managers.default.extend( args ); + }; + + /** + * Returns a manager view. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return object + */ + api.views.get_manager = function( type ) { + + if ( this.manager_exists( type ) ) + return this.managers[ type ]; + + return this.managers.default; + }; + + /** + * Removes a manager view. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return void + */ + api.views.unregister_manager = function( type ) { + + if ( 'default' !== type && this.manager_exists( type ) ) + delete this.managers[ type ]; + }; + + /** + * Checks if a manager view exists. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return bool + */ + api.views.manager_exists = function( type ) { + + return this.managers.hasOwnProperty( type ); + }; + + /** + * Creates a new section view. + * + * @since 1.0.0 + * @access public + * @param string $type + * @param object $args + * @return void + */ + api.views.register_section = function( type, args ) { + + if ( 'default' !== type ) + this.sections[ type ] = this.sections.default.extend( args ); + }; + + /** + * Returns a section view. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return object + */ + api.views.get_section = function( type ) { + + if ( this.section_exists( type ) ) + return this.sections[ type ]; + + return this.sections.default; + }; + + /** + * Removes a section view. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return void + */ + api.views.unregister_section = function( type ) { + + if ( 'default' !== type && this.section_exists( type ) ) + delete this.sections[ type ]; + }; + + /** + * Checks if a section view exists. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return bool + */ + api.views.section_exists = function( type ) { + + return this.sections.hasOwnProperty( type ); + }; + + /** + * Creates a new control view. + * + * @since 1.0.0 + * @access public + * @param string $type + * @param object $args + * @return void + */ + api.views.register_control = function( type, args ) { + + if ( 'default' !== type ) + this.controls[ type ] = this.controls.default.extend( args ); + }; + + /** + * Returns a control view. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return object + */ + api.views.get_control = function( type ) { + + if ( this.control_exists( type ) ) + return this.controls[ type ]; + + return this.controls.default; + }; + + /** + * Removes a control view. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return void + */ + api.views.unregister_control = function( type ) { + + if ( 'default' !== type && this.control_exists( type ) ) + delete this.controls[ type ]; + }; + + /** + * Checks if a control view exists. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return bool + */ + api.views.control_exists = function( type ) { + + return this.controls.hasOwnProperty( type ); + }; + + /** + * Creates a new manager template. + * + * @since 1.0.0 + * @access public + * @param string $type + * @param object $args + * @return void + */ + api.templates.register_manager = function( type ) { + + this.managers[ type ] = wp.template( 'butterbean-manager-' + type ); + }; + + /** + * Returns a manager template. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return function + */ + api.templates.get_manager = function( type ) { + + return this.manager_exists( type ) ? this.managers[ type ] : false; + }; + + /** + * Removes a manager template. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return void + */ + api.templates.unregister_manager = function( type ) { + + if ( this.manager_exists( type ) ) + delete this.managers[ type ]; + }; + + /** + * Checks if a manager template exists. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return bool + */ + api.templates.manager_exists = function( type ) { + + return this.managers.hasOwnProperty( type ); + }; + + /** + * Creates a new section template. + * + * @since 1.0.0 + * @access public + * @param string $type + * @param object $args + * @return void + */ + api.templates.register_section = function( type ) { + + this.sections[ type ] = wp.template( 'butterbean-section-' + type ); + }; + + /** + * Returns a section template. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return function + */ + api.templates.get_section = function( type ) { + + return this.section_exists( type ) ? this.sections[ type ] : false; + }; + + /** + * Removes a section template. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return void + */ + api.templates.unregister_section = function( type ) { + + if ( this.section_exists( type ) ) + delete this.sections[ type ]; + }; + + /** + * Checks if a section template exists. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return bool + */ + api.templates.section_exists = function( type ) { + + return this.sections.hasOwnProperty( type ); + }; + + /** + * Creates a new control template. + * + * @since 1.0.0 + * @access public + * @param string $type + * @param object $args + * @return void + */ + api.templates.register_control = function( type ) { + + this.controls[ type ] = wp.template( 'butterbean-control-' + type ); + }; + + /** + * Returns a control template. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return function + */ + api.templates.get_control = function( type ) { + + return this.control_exists( type ) ? this.controls[ type ] : false; + }; + + /** + * Removes a control template. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return void + */ + api.templates.unregister_control = function( type ) { + + if ( this.control_exists( type ) ) + delete this.controls[ type ]; + }; + + /** + * Checks if a control template exists. + * + * @since 1.0.0 + * @access public + * @param string $type + * @return bool + */ + api.templates.control_exists = function( type ) { + + return this.controls.hasOwnProperty( type ); + }; + + /** + * Renders our managers, sections, and controls. + * + * @since 1.0.0 + * @access private + * @return void + */ + api.render = function() { + + // Loop through each of the managers and render their api.views. + _.each( butterbean_data.managers, function( data ) { + + // Create a new manager model with the JSON data for the manager. + var manager = new Manager( data ); + + // Get the manager view callback. + var callback = api.views.get_manager( data.type ); + + // Create a new manager view. + var view = new callback( { model : manager } ); + + // Get the meta box element. + var metabox = document.getElementById( 'butterbean-ui-' + manager.get( 'name' ) ); + + // Add the `.butterbean-ui` class to the meta box. + metabox.className += ' butterbean-ui'; + + // Render the manager view. + metabox.querySelector( '.inside' ).appendChild( view.render().el ); + + // Render the manager subviews. + view.subview_render(); + + // Call the view's ready method. + view.ready(); + } ); + }; + + /* === Templates === */ + + // Nav template. + var nav_template = wp.template( 'butterbean-nav' ); + + /* === Models === */ + + // Manager model (each manager is housed within a meta box). + var Manager = Backbone.Model.extend( { + defaults : { + name : '', + type : '', + sections : {}, + controls : {} + } + } ); + + // Section model (each section belongs to a manager). + var Section = Backbone.Model.extend( { + defaults : { + name : '', + type : '', + label : '', + description : '', + icon : '', + manager : '', + active : '', + selected : false + } + } ); + + // Control model (each control belongs to a manager and section). + var Control = Backbone.Model.extend( { + defaults : { + name : '', + type : '', + label : '', + description : '', + icon : '', + value : '', + choices : {}, + attr : '', + active : '', + manager : '', + section : '', + setting : '' + } + } ); + + /* === Collections === */ + + /** + * Stores our collection of section models. + * + * @since 1.0.0 + * @access private + * @var object + */ + var Sections = Backbone.Collection.extend( { + model : Section + } ); + + /* === Views === */ + + /** + * The default manager view. Other views can extend this using the + * `butterbean.views.register_manager()` function. + * + * @since 1.0.0 + * @access public + * @var object + */ + api.views.managers[ 'default' ] = Backbone.View.extend( { + + // Wrapper element for the manager view. + tagName : 'div', + + // Adds some custom attributes to the wrapper. + attributes : function() { + return { + 'id' : 'butterbean-manager-' + this.model.get( 'name' ), + 'class' : 'butterbean-manager butterbean-manager-' + this.model.get( 'type' ) + }; + }, + + // Initializes the view. + initialize : function() { + + var type = this.model.get( 'type' ); + + // If there's not yet a template for this manager type, create it. + if ( ! api.templates.manager_exists( type ) ) + api.templates.register_manager( type ); + + // Get the manager template. + this.template = api.templates.get_manager( type ); + }, + + // Renders the manager. + render : function() { + this.el.innerHTML = this.template( this.model.toJSON() ); + return this; + }, + + // Renders the manager's sections and controls. + // Important! This may change drastically in the future, possibly even + // taken out of the manager view altogether. It's for this reason that + // it's not recommended to create custom views for managers right now. + subview_render : function() { + + // Create a new section collection. + var sections = new Sections(); + + // Loop through each section and add it to the collection. + _.each( this.model.get( 'sections' ), function( data ) { + + sections.add( new Section( data ) ); + } ); + + // Loop through each section in the collection and render its view. + sections.forEach( function( section, i ) { + + // Create a new nav item view for the section. + var nav_view = new Nav_View( { model : section } ); + + // Render the nav item view. + document.querySelector( '#butterbean-ui-' + section.get( 'manager' ) + ' .butterbean-nav' ).appendChild( nav_view.render().el ); + + // Get the section view callback. + var callback = api.views.get_section( section.attributes.type ); + + // Create a new section view. + var view = new callback( { model : section } ); + + // Render the section view. + document.querySelector( '#butterbean-ui-' + section.get( 'manager' ) + ' .butterbean-content' ).appendChild( view.render().el ); + + // Call the section view's ready method. + view.ready(); + + // If the first model, set it to selected. + section.set( 'selected', 0 === i ); + }, this ); + + // Loop through each control for the manager and render its view. + _.each( this.model.get( 'controls' ), function( data ) { + + // Create a new control model. + var control = new Control( data ); + + // Get the control view callback. + var callback = api.views.get_control( data.type ); + + // Create a new control view. + var view = new callback( { model : control } ); + + // Render the view. + document.getElementById( 'butterbean-' + control.get( 'manager' ) + '-section-' + control.get( 'section' ) ).appendChild( view.render().el ); + + // Call the view's ready method. + view.ready(); + } ); + + return this; + }, + + // Function that is executed *after* the view has been rendered. + // This is meant to be overwritten in sub-views. + ready : function() {} + } ); + + /** + * The default section view. Other views can extend this using the + * `butterbean.views.register_section()` function. + * + * @since 1.0.0 + * @access public + * @var object + */ + api.views.sections[ 'default' ] = Backbone.View.extend( { + + // Wrapper element for the section. + tagName : 'div', + + // Adds custom attributes for the section wrapper. + attributes : function() { + return { + 'id' : 'butterbean-' + this.model.get( 'manager' ) + '-section-' + this.model.get( 'name' ), + 'class' : 'butterbean-section butterbean-section-' + this.model.get( 'type' ), + 'aria-hidden' : ! this.model.get( 'selected' ) + }; + }, + + // Initializes the view. + initialize : function() { + + // Add an event for when the model changes. + this.model.on( 'change', this.onchange, this ); + + // Get the section type. + var type = this.model.get( 'type' ); + + // If there's no template for this section type, create it. + if ( ! api.templates.section_exists( type ) ) + api.templates.register_section( type ); + + // Gets the section template. + this.template = api.templates.get_section( type ); + }, + + // Renders the section. + render : function() { + + // Only render template if model is active. + if ( this.model.get( 'active' ) ) + this.el.innerHTML = this.template( this.model.toJSON() ); + + return this; + }, + + // Executed when the model changes. + onchange : function() { + + // Set the view's `aria-hidden` attribute based on whether the model is selected. + this.el.setAttribute( 'aria-hidden', ! this.model.get( 'selected' ) ); + }, + + // Function that is executed *after* the view has been rendered. + // This is meant to be overwritten in sub-views. + ready : function() {} + } ); + + /** + * The nav item view for each section. + * + * @since 1.0.0 + * @access public + * @var object + */ + var Nav_View = Backbone.View.extend( { + + // Sets the template used. + template : nav_template, + + // Wrapper element for the nav item. + tagName : 'li', + + // Sets some custom attributes for the nav item wrapper. + attributes : function() { + return { + 'aria-selected' : this.model.get( 'selected' ) + }; + }, + + // Initializes the nav item view. + initialize : function() { + this.model.on( 'change', this.render, this ); + this.model.on( 'change', this.onchange, this ); + }, + + // Renders the nav item. + render : function() { + + // Only render template if model is active. + if ( this.model.get( 'active' ) ) + this.el.innerHTML = this.template( this.model.toJSON() ); + + return this; + }, + + // Custom events. + events : { + 'click a' : 'onselect' + }, + + // Executed when the section model changes. + onchange : function() { + + // Set the `aria-selected` attibute based on the model selected state. + this.el.setAttribute( 'aria-selected', this.model.get( 'selected' ) ); + }, + + // Executed when the link for the nav item is clicked. + onselect : function( event ) { + event.preventDefault(); + + // Loop through each of the models in the collection and set them to inactive. + _.each( this.model.collection.models, function( m ) { + + m.set( 'selected', false ); + }, this ); + + // Set this view's model to selected. + this.model.set( 'selected', true ); + } + } ); + + /** + * The default control view. Other views can extend this using the + * `butterbean.views.register_control()` function. + * + * @since 1.0.0 + * @access public + * @var object + */ + api.views.controls[ 'default' ] = Backbone.View.extend( { + + // Wrapper element for the control. + tagName : 'div', + + // Custom attributes for the control wrapper. + attributes : function() { + return { + 'id' : 'butterbean-control-' + this.model.get( 'name' ), + 'class' : 'butterbean-control butterbean-control-' + this.model.get( 'type' ) + }; + }, + + // Initiazlies the control view. + initialize : function() { + var type = this.model.get( 'type' ); + + // Only add a new control template if we have a different control type. + if ( ! api.templates.control_exists( type ) ) + api.templates.register_control( type ); + + // Get the control template. + this.template = api.templates.get_control( type ); + + // Bind changes so that the view is re-rendered when the model changes. + _.bindAll( this, 'render' ); + this.model.bind( 'change', this.render ); + }, + + // Renders the control template. + render : function() { + + // Only render template if model is active. + if ( this.model.get( 'active' ) ) + this.el.innerHTML = this.template( this.model.toJSON() ); + + return this; + }, + + // Function that is executed *after* the view has been rendered. + // This is meant to be overwritten in sub-views. + ready : function() {} + } ); + + /** + * Adds the color control view. + * + * @since 1.0.0 + */ + api.views.register_control( 'color', { + + // Calls the core WP color picker for the control's input. + ready : function() { + + var options = this.model.attributes.options; + + jQuery( this.$el ).find( '.butterbean-color-picker' ).wpColorPicker( options ); + } + } ); + + /** + * Adds the color palette view. + * + * @since 1.0.0 + */ + api.views.register_control( 'palette', { + + // Adds custom events. + events : { + 'change input' : 'onselect' + }, + + // Executed when one of the color palette's value has changed. + // These are radio inputs. + onselect : function() { + + // Get the value of the input. + var value = document.querySelector( '#' + this.el.id + ' input:checked' ).getAttribute( 'value' ); + + // Get all choices. + var choices = this.model.get( 'choices' ); + + // Loop through choices and change the selected value. + _.each( choices, function( choice, key ) { + choice.selected = key === value; + } ); + + // Because `choices` is an array, it's not recognized as a change. So, we + // have to manually trigger a change here so that the view gets re-rendered. + this.model.set( 'choices', choices ).trigger( 'change', this.model ); + } + } ); + + /** + * Adds the image control view. + * + * @since 1.0.0 + */ + api.views.register_control( 'image', { + + // Adds custom events. + events : { + 'click .butterbean-add-media' : 'showmodal', + 'click .butterbean-change-media' : 'showmodal', + 'click .butterbean-remove-media' : 'removemedia' + }, + + // Executed when the show modal button is clicked. + showmodal : function() { + + + // If we already have a media modal, open it. + if ( ! _.isUndefined( this.media_modal ) ) { + + this.media_modal.open(); + return; + } + + // Create a new media modal. + this.media_modal = wp.media( { + frame : 'select', + multiple : false, + editing : true, + title : this.model.get( 'l10n' ).choose, + library : { type : 'image' }, + button : { text: this.model.get( 'l10n' ).set } + } ); + + // Runs when an image is selected in the media modal. + this.media_modal.on( 'select', function() { + + // Gets the JSON data for the first selection. + var media = this.media_modal.state().get( 'selection' ).first().toJSON(); + + // Size of image to display. + var size = this.model.attributes.size; + + // Updates the model for the view. + this.model.set( { + src : media.sizes[ size ] ? media.sizes[ size ]['url'] : media.url, + alt : media.alt, + value : media.id + } ); + }, this ); + + // Opens the media modal. + this.media_modal.open(); + }, + + // Executed when the remove media button is clicked. + removemedia : function() { + + // Updates the model for the view. + this.model.set( { src : '', alt : '', value : '' } ); + } + } ); + +}() ); diff --git a/admin/butterbean/js/butterbean.min.js b/admin/butterbean/js/butterbean.min.js new file mode 100644 index 0000000..302aaee --- /dev/null +++ b/admin/butterbean/js/butterbean.min.js @@ -0,0 +1 @@ +window.butterbean=window.butterbean||{},function(){if(!_.isUndefined(butterbean_data)){var e=butterbean={views:{managers:{},sections:{},controls:{}},templates:{managers:{},sections:{},controls:{}}};e.views.register_manager=function(e,t){"default"!==e&&(this.managers[e]=this.managers.default.extend(t))},e.views.get_manager=function(e){return this.manager_exists(e)?this.managers[e]:this.managers.default},e.views.unregister_manager=function(e){"default"!==e&&this.manager_exists(e)&&delete this.managers[e]},e.views.manager_exists=function(e){return this.managers.hasOwnProperty(e)},e.views.register_section=function(e,t){"default"!==e&&(this.sections[e]=this.sections.default.extend(t))},e.views.get_section=function(e){return this.section_exists(e)?this.sections[e]:this.sections.default},e.views.unregister_section=function(e){"default"!==e&&this.section_exists(e)&&delete this.sections[e]},e.views.section_exists=function(e){return this.sections.hasOwnProperty(e)},e.views.register_control=function(e,t){"default"!==e&&(this.controls[e]=this.controls.default.extend(t))},e.views.get_control=function(e){return this.control_exists(e)?this.controls[e]:this.controls.default},e.views.unregister_control=function(e){"default"!==e&&this.control_exists(e)&&delete this.controls[e]},e.views.control_exists=function(e){return this.controls.hasOwnProperty(e)},e.templates.register_manager=function(e){this.managers[e]=wp.template("butterbean-manager-"+e)},e.templates.get_manager=function(e){return this.manager_exists(e)?this.managers[e]:!1},e.templates.unregister_manager=function(e){this.manager_exists(e)&&delete this.managers[e]},e.templates.manager_exists=function(e){return this.managers.hasOwnProperty(e)},e.templates.register_section=function(e){this.sections[e]=wp.template("butterbean-section-"+e)},e.templates.get_section=function(e){return this.section_exists(e)?this.sections[e]:!1},e.templates.unregister_section=function(e){this.section_exists(e)&&delete this.sections[e]},e.templates.section_exists=function(e){return this.sections.hasOwnProperty(e)},e.templates.register_control=function(e){this.controls[e]=wp.template("butterbean-control-"+e)},e.templates.get_control=function(e){return this.control_exists(e)?this.controls[e]:!1},e.templates.unregister_control=function(e){this.control_exists(e)&&delete this.controls[e]},e.templates.control_exists=function(e){return this.controls.hasOwnProperty(e)},e.render=function(){_.each(butterbean_data.managers,function(t){var i=new n(t),s=e.views.get_manager(t.type),a=new s({model:i}),o=document.getElementById("butterbean-ui-"+i.get("name"));o.className+=" butterbean-ui",o.querySelector(".inside").appendChild(a.render().el),a.subview_render(),a.ready()})};var t=wp.template("butterbean-nav"),n=Backbone.Model.extend({defaults:{name:"",type:"",sections:{},controls:{}}}),i=Backbone.Model.extend({defaults:{name:"",type:"",label:"",description:"",icon:"",manager:"",active:"",selected:!1}}),s=Backbone.Model.extend({defaults:{name:"",type:"",label:"",description:"",icon:"",value:"",choices:{},attr:"",active:"",manager:"",section:"",setting:""}}),a=Backbone.Collection.extend({model:i});e.views.managers["default"]=Backbone.View.extend({tagName:"div",attributes:function(){return{id:"butterbean-manager-"+this.model.get("name"),"class":"butterbean-manager butterbean-manager-"+this.model.get("type")}},initialize:function(){var t=this.model.get("type");e.templates.manager_exists(t)||e.templates.register_manager(t),this.template=e.templates.get_manager(t)},render:function(){return this.el.innerHTML=this.template(this.model.toJSON()),this},subview_render:function(){var t=new a;return _.each(this.model.get("sections"),function(e){t.add(new i(e))}),t.forEach(function(t,n){var i=new o({model:t});document.querySelector("#butterbean-ui-"+t.get("manager")+" .butterbean-nav").appendChild(i.render().el);var s=e.views.get_section(t.attributes.type),a=new s({model:t});document.querySelector("#butterbean-ui-"+t.get("manager")+" .butterbean-content").appendChild(a.render().el),a.ready(),t.set("selected",0===n)},this),_.each(this.model.get("controls"),function(t){var n=new s(t),i=e.views.get_control(t.type),a=new i({model:n});document.getElementById("butterbean-"+n.get("manager")+"-section-"+n.get("section")).appendChild(a.render().el),a.ready()}),this},ready:function(){}}),e.views.sections["default"]=Backbone.View.extend({tagName:"div",attributes:function(){return{id:"butterbean-"+this.model.get("manager")+"-section-"+this.model.get("name"),"class":"butterbean-section butterbean-section-"+this.model.get("type"),"aria-hidden":!this.model.get("selected")}},initialize:function(){this.model.on("change",this.onchange,this);var t=this.model.get("type");e.templates.section_exists(t)||e.templates.register_section(t),this.template=e.templates.get_section(t)},render:function(){return this.model.get("active")&&(this.el.innerHTML=this.template(this.model.toJSON())),this},onchange:function(){this.el.setAttribute("aria-hidden",!this.model.get("selected"))},ready:function(){}});var o=Backbone.View.extend({template:t,tagName:"li",attributes:function(){return{"aria-selected":this.model.get("selected")}},initialize:function(){this.model.on("change",this.render,this),this.model.on("change",this.onchange,this)},render:function(){return this.model.get("active")&&(this.el.innerHTML=this.template(this.model.toJSON())),this},events:{"click a":"onselect"},onchange:function(){this.el.setAttribute("aria-selected",this.model.get("selected"))},onselect:function(e){e.preventDefault(),_.each(this.model.collection.models,function(e){e.set("selected",!1)},this),this.model.set("selected",!0)}});e.views.controls["default"]=Backbone.View.extend({tagName:"div",attributes:function(){return{id:"butterbean-control-"+this.model.get("name"),"class":"butterbean-control butterbean-control-"+this.model.get("type")}},initialize:function(){var t=this.model.get("type");e.templates.control_exists(t)||e.templates.register_control(t),this.template=e.templates.get_control(t),_.bindAll(this,"render"),this.model.bind("change",this.render)},render:function(){return this.model.get("active")&&(this.el.innerHTML=this.template(this.model.toJSON())),this},ready:function(){}}),e.views.register_control("color",{ready:function(){var e=this.model.attributes.options;jQuery(this.$el).find(".butterbean-color-picker").wpColorPicker(e)}}),e.views.register_control("palette",{events:{"change input":"onselect"},onselect:function(){var e=document.querySelector("#"+this.el.id+" input:checked").getAttribute("value"),t=this.model.get("choices");_.each(t,function(t,n){t.selected=n===e}),this.model.set("choices",t).trigger("change",this.model)}}),e.views.register_control("image",{events:{"click .butterbean-add-media":"showmodal","click .butterbean-change-media":"showmodal","click .butterbean-remove-media":"removemedia"},showmodal:function(){return _.isUndefined(this.media_modal)?(this.media_modal=wp.media({frame:"select",multiple:!1,editing:!0,title:this.model.get("l10n").choose,library:{type:"image"},button:{text:this.model.get("l10n").set}}),this.media_modal.on("select",function(){var e=this.media_modal.state().get("selection").first().toJSON(),t=this.model.attributes.size;this.model.set({src:e.sizes[t]?e.sizes[t].url:e.url,alt:e.alt,value:e.id})},this),this.media_modal.open(),void 0):(this.media_modal.open(),void 0)},removemedia:function(){this.model.set({src:"",alt:"",value:""})}})}}(); \ No newline at end of file diff --git a/admin/butterbean/license.md b/admin/butterbean/license.md new file mode 100644 index 0000000..7e14f38 --- /dev/null +++ b/admin/butterbean/license.md @@ -0,0 +1,339 @@ + 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. + + + Copyright (C) + + 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. + + , 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 diff --git a/admin/butterbean/readme.md b/admin/butterbean/readme.md new file mode 100644 index 0000000..e601f1a --- /dev/null +++ b/admin/butterbean/readme.md @@ -0,0 +1,152 @@ +# ButterBean + +ButterBean is a neat little post meta box framework built on [Backbone.js](http://backbonejs.org) and [Underscore.js](http://underscorejs.org). You can run it as a standalone plugin or drop it into your own plugins. + +The idea behind ButterBean came about because I often build custom post types that need quite a bit of custom metadata attached to the posts. Separating this into multiple meta boxes wasn't fun or user friendly. So, I decided to go with a single tabbed meta box instead. + +And, that's what ButterBean is. It's essentially a meta box with tabs for lots of content. + +## Just the interface + +A lot of meta box frameworks try to do everything. They handle backend output, frontend output, and everything else you can think of. ButterBean is meant to be an interface only. Because every project's needs are vastly different, it doesn't make sense to stick you with a bunch of things you don't need. This means that the code can stay relatively lean and flexible, which makes it perfect for bundling in your plugins. + +So, don't go looking for functions for outputting metadata on the front end from ButterBean. It doesn't have any. Use the core WordPress functionality or build your own wrapper functions. + +## Documentation + +This is a quick guide. If you're familiar with the WordPress Customization API, you should probably pick this up fairly quickly. A lot of the same concepts are used here. + +### Installation + +Drop the `butterbean` folder into your plugin. That's the simple part. + +The script will auto-load itself on the correct admin hooks. You just need to load it like so: + +``` +add_action( 'plugins_loaded', 'th_load' ); + +function th_load() { + + require_once( 'path/to/butterbean/butterbean.php' ); +} +``` + +### Registration + +There's a built-in action hook called `butterbean_register`. You're going to use that to register everything. So, you need to set up a callback function for that. + +``` +add_action( 'butterbean_register', 'th_register', 10, 2 ); + +function th_register( $butterbean, $post_type ) { + + // Register managers, sections, controls, and settings here. +} +``` + +#### Registering a manager + +A **manager** is a group of sections, controls, and settings. It's displayed as a single meta box. There can be multiple managers per screen (don't try multiples yet). + +``` +$butterbean->register_manager( + 'example', + array( + 'label' => esc_html__( 'Example', 'your-textdomain' ), + 'post_type' => 'your_post_type', + 'context' => 'normal', + 'priority' => 'high' + ) +); + +$manager = $butterbean->get_manager( 'example' ); +``` + +#### Registering a section + +A **section** is a group of controls within a manager. They are presented as "tabbed" sections in the UI. + +``` +$manager->register_section( + 'section_1', + array( + 'label' => esc_html__( 'Section 1', 'your-textdomain' ), + 'icon' => 'dashicons-admin-generic' + ) +); +``` + +#### Registering a control + +A **control** is essentially a form field. It's the field(s) that a user enters data into. Each control belongs to a section. Each control should also be tied to a setting (below). + +``` +$manager->register_control( + 'abc_xyz', // Same as setting name. + array( + 'type' => 'text', + 'section' => 'section_1', + 'label' => esc_html__( 'Control ABC', 'your-textdomain' ), + 'attr' => array( 'class' => 'widefat' ) + ) +); +``` + +#### Registering a setting + +A **setting** is nothing more than some post metadata and how it gets stored. A setting belongs to a specific control. + +``` +$manager->register_setting( + 'abc_xyz', // Same as control name. + array( + 'sanitize_callback' => 'wp_filter_nohtml_kses' + ) +); +``` + +### JavaScript API + +ButterBean was built using [Backbone](http://backbonejs.org) for handling models, collections, and views. It uses [Underscore](http://underscorejs.org) for rendering templates for the views. All output is handled via JavaScript rather than PHP so that we can do cool stuff on the fly without having to reload the page. This is particularly useful when you start building more complex controls. + +You'll never need to touch JavaScript until you need to build a control that relies on JavaScript. + +#### The butterbean object + +`butterbean` is the global object that houses everything you ever want to touch on the JavaScript side of things. It's located in the `js/butterbean.js` file. This file is well-documented, so you'll want to dive into it for doing more advanced stuff. + +`butterbean.views.register_control()` is what most people will end up using. It's a function for registering a custom control view. New views can be created for each `type` of control. + +Here's a quick example of registering a view for a color control where we need to call the core WordPress `wpColorPicker()` function. It uses the `ready()` function, which is fired after the HTML has been rendered for the view. + +``` +( function() { + + butterbean.views.register_control( 'color', { + + // Calls the core WP color picker for the control's input. + ready : function() { + + var options = this.model.attributes.options; + + jQuery( this.$el ).find( '.butterbean-color-picker' ).wpColorPicker( options ); + } + } ); +}() ); +``` + +## Professional Support + +If you need professional plugin support from me, the plugin author, you can access the support forums at [Theme Hybrid](http://themehybrid.com/board/topics), which is a professional WordPress help/support site where I handle support for all my plugins and themes for a community of 70,000+ users (and growing). + +## Copyright and License + +Various ideas from different projects have made their way into ButterBean. A few of the projects that had an important impact on the direction of this project are: + +* Architecturally, the PHP code was modeled after the core WordPress Customization API. - [GPL 2+](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) +* The design concept of the default tabbed interface was taken from [WooCommerce](http://www.woothemes.com/woocommerce/). © WooThemes - [GPL 3+](http://www.gnu.org/licenses/gpl.html) +* Code ideas for the media frame were borrowed from [WP Term Images](https://wordpress.org/plugins/wp-term-images/). © John James Jacoby - [GPL 2+](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + +This project is licensed under the [GNU GPL](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html), version 2 or later. + +2015-2016 © [Justin Tadlock](http://justintadlock.com). diff --git a/admin/butterbean/screenshot-1.png b/admin/butterbean/screenshot-1.png new file mode 100644 index 0000000000000000000000000000000000000000..8937e92746776dec7a4be4699403cfc3b292c641 GIT binary patch literal 21854 zcmbrlWmsI>wk=9l77!#5f`wqggFA&2EI0&r2=4A4f+V=RRB(4G+}+&@D4aqHcfG~h zXYcpj^WJyg`QH0AYs?z651oDV)_R*E-{d9UqJBh0KtOmaB`KzafbiM~0pXSIo4??9 zUbT=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;J&-}|Jw-spO+CC`c!IqYjvjqw%90%L}04`;70C2Ct#r3rIu*!#xih9yl6iFAkG z#^*u=tS-K@)PQ3opyQP05|Sm>+wpmkLrfvPew^N*L~&_~qEIW8tJ&U*fvse;{cR3% zhJjWOOW5fZfb3UVe4)^^>szXmbW)r=ybg@0$;axo-RJ3fTrZfFpqJQ)~Q_gAWc( z_7akWlwd)dD#&XCZl|Vwqd78x}3km@AdMAR8 z4+&&4nMfoKX3Lk4h-es%A0?Z+oroNgKjq(VobsOTj$Tl3eZH*ueiY{Ga(K@~R(2wJ z4f|vA3=LU|2Nci%pfuq0y27%_$BYNqJh6clt=$1_?tKtK_+xzWZYaE`RqqN-Fw+Tw zr=>oc+U~mmoBK)r)M~XF^?n_`Q@@+3UckcW*UY`Ne~t$3kOgXQ!y|!=W$;$;7zBVf z7M#B<$bMnCU*PU9IP-rm{H6H#W#0Lh2ih;v@IMNJd2l-26HaoZhQn?E#UX!>(A4@|yrLpn{DV2Dcdnu71+v q;4=k~*k3sG|Jl?}B81knmucXo + checked="checked" <# } #> /> + + <# if ( data.label ) { #> + {{ data.label }} + <# } #> + + <# if ( data.description ) { #> + {{{ data.description }}} + <# } #> + diff --git a/admin/butterbean/tmpl/control-checkboxes.php b/admin/butterbean/tmpl/control-checkboxes.php new file mode 100644 index 0000000..51db842 --- /dev/null +++ b/admin/butterbean/tmpl/control-checkboxes.php @@ -0,0 +1,22 @@ +<# if ( data.label ) { #> + {{ data.label }} +<# } #> + +<# if ( data.description ) { #> + {{{ data.description }}} +<# } #> + +

    + + <# _.each( data.choices, function( label, choice ) { #> + +
  • + +
  • + + <# } ) #> + +
diff --git a/admin/butterbean/tmpl/control-color.php b/admin/butterbean/tmpl/control-color.php new file mode 100644 index 0000000..1e6161f --- /dev/null +++ b/admin/butterbean/tmpl/control-color.php @@ -0,0 +1,11 @@ + diff --git a/admin/butterbean/tmpl/control-date.php b/admin/butterbean/tmpl/control-date.php new file mode 100644 index 0000000..d78c7c9 --- /dev/null +++ b/admin/butterbean/tmpl/control-date.php @@ -0,0 +1,55 @@ +<# if ( data.label ) { #> + {{ data.label }} +<# } #> + +<# if ( data.description ) { #> + {{{ data.description }}} +<# } #> + + + {{ data.month.label }} + +'; + +$day = ''; + +$year = ''; + +$hour = ''; + +$minute = ''; + +$second = ''; ?> + +<# if ( data.show_time ) { #> + + + +<# } else { #> + + + +<# } #> diff --git a/admin/butterbean/tmpl/control-datetime.php b/admin/butterbean/tmpl/control-datetime.php new file mode 100644 index 0000000..d78c7c9 --- /dev/null +++ b/admin/butterbean/tmpl/control-datetime.php @@ -0,0 +1,55 @@ +<# if ( data.label ) { #> + {{ data.label }} +<# } #> + +<# if ( data.description ) { #> + {{{ data.description }}} +<# } #> + + + {{ data.month.label }} + +'; + +$day = ''; + +$year = ''; + +$hour = ''; + +$minute = ''; + +$second = ''; ?> + +<# if ( data.show_time ) { #> + + + +<# } else { #> + + + +<# } #> diff --git a/admin/butterbean/tmpl/control-image.php b/admin/butterbean/tmpl/control-image.php new file mode 100644 index 0000000..c519994 --- /dev/null +++ b/admin/butterbean/tmpl/control-image.php @@ -0,0 +1,24 @@ +<# if ( data.label ) { #> + {{ data.label }} +<# } #> + +<# if ( data.description ) { #> + {{{ data.description }}} +<# } #> + + + +<# if ( data.src ) { #> + {{ data.alt }} +<# } else { #> +
{{ data.l10n.placeholder }}
+<# } #> + +

+ <# if ( data.src ) { #> + + + <# } else { #> + + <# } #> +

diff --git a/admin/butterbean/tmpl/control-multi-avatars.php b/admin/butterbean/tmpl/control-multi-avatars.php new file mode 100644 index 0000000..f27220a --- /dev/null +++ b/admin/butterbean/tmpl/control-multi-avatars.php @@ -0,0 +1,23 @@ +<# if ( data.label ) { #> + {{ data.label }} +<# } #> + +<# if ( data.description ) { #> + {{{ data.description }}} +<# } #> + +
+ + <# _.each( data.choices, function( user ) { #> + + + + <# } ) #> + +
diff --git a/admin/butterbean/tmpl/control-palette.php b/admin/butterbean/tmpl/control-palette.php new file mode 100644 index 0000000..5724c46 --- /dev/null +++ b/admin/butterbean/tmpl/control-palette.php @@ -0,0 +1,23 @@ +<# if ( data.label ) { #> + {{ data.label }} +<# } #> + +<# if ( data.description ) { #> + {{{ data.description }}} +<# } #> + +<# _.each( data.choices, function( palette, choice ) { #> + +<# } ) #> diff --git a/admin/butterbean/tmpl/control-parent.php b/admin/butterbean/tmpl/control-parent.php new file mode 100644 index 0000000..2ba69bf --- /dev/null +++ b/admin/butterbean/tmpl/control-parent.php @@ -0,0 +1,17 @@ + diff --git a/admin/butterbean/tmpl/control-radio-image.php b/admin/butterbean/tmpl/control-radio-image.php new file mode 100644 index 0000000..89c0ad2 --- /dev/null +++ b/admin/butterbean/tmpl/control-radio-image.php @@ -0,0 +1,17 @@ +<# if ( data.label ) { #> + {{ data.label }} +<# } #> + +<# if ( data.description ) { #> + {{{ data.description }}} +<# } #> + +<# _.each( data.choices, function( args, choice ) { #> + + + +<# } ) #> diff --git a/admin/butterbean/tmpl/control-radio.php b/admin/butterbean/tmpl/control-radio.php new file mode 100644 index 0000000..baacbaa --- /dev/null +++ b/admin/butterbean/tmpl/control-radio.php @@ -0,0 +1,22 @@ +<# if ( data.label ) { #> + {{ data.label }} +<# } #> + +<# if ( data.description ) { #> + {{{ data.description }}} +<# } #> + +
    + + <# _.each( data.choices, function( label, choice ) { #> + +
  • + +
  • + + <# } ) #> + +
diff --git a/admin/butterbean/tmpl/control-select-group.php b/admin/butterbean/tmpl/control-select-group.php new file mode 100644 index 0000000..49652e0 --- /dev/null +++ b/admin/butterbean/tmpl/control-select-group.php @@ -0,0 +1,33 @@ + diff --git a/admin/butterbean/tmpl/control-select.php b/admin/butterbean/tmpl/control-select.php new file mode 100644 index 0000000..1cfbb04 --- /dev/null +++ b/admin/butterbean/tmpl/control-select.php @@ -0,0 +1,20 @@ + diff --git a/admin/butterbean/tmpl/control-textarea.php b/admin/butterbean/tmpl/control-textarea.php new file mode 100644 index 0000000..07f9e4b --- /dev/null +++ b/admin/butterbean/tmpl/control-textarea.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/admin/butterbean/tmpl/control.php b/admin/butterbean/tmpl/control.php new file mode 100644 index 0000000..f069e5c --- /dev/null +++ b/admin/butterbean/tmpl/control.php @@ -0,0 +1,11 @@ + diff --git a/admin/butterbean/tmpl/manager.php b/admin/butterbean/tmpl/manager.php new file mode 100644 index 0000000..f25fa17 --- /dev/null +++ b/admin/butterbean/tmpl/manager.php @@ -0,0 +1,2 @@ +
    +
    diff --git a/admin/butterbean/tmpl/nav.php b/admin/butterbean/tmpl/nav.php new file mode 100644 index 0000000..afe13ad --- /dev/null +++ b/admin/butterbean/tmpl/nav.php @@ -0,0 +1 @@ +{{ data.label }} diff --git a/admin/butterbean/tmpl/section.php b/admin/butterbean/tmpl/section.php new file mode 100644 index 0000000..b89491b --- /dev/null +++ b/admin/butterbean/tmpl/section.php @@ -0,0 +1,3 @@ +<# if ( data.description ) { #> + {{{ data.description }}} +<# } #> diff --git a/admin/css/admin.css b/admin/css/admin.css new file mode 100644 index 0000000..aa6811b --- /dev/null +++ b/admin/css/admin.css @@ -0,0 +1,46 @@ +#butterbean-control-taxonomy, +#butterbean-control-terms { + display: none; +} + +#butterbean-ui-wp_show_posts input, +#butterbean-ui-wp_show_posts select, +#butterbean-ui-wp_show_posts textarea { + padding: 10px; + width: 100%; + height: auto; +} + +.wpsp-pro { + background: orange; + padding: 5px; + color: white; + font-size: 80%; +} + +#butterbean-ui-wp_show_posts .butterbean-control-color input { + width: 80px; + padding: 3px 5px; + line-height: 16px; +} + +#butterbean-ui-wp_show_posts input[type="checkbox"] { + width: auto; + height: 16px; +} + +.mce-i-wpsp-add-icon:before { + content: "\f163"; + font: normal 20px/1 'dashicons'; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +#butterbean-control-wpsp_tax_term .butterbean-checkbox-list { + display: -webkit-flex; + display: flex; + -webkit-flex-flow: wrap column; + flex-flow: wrap column; + max-height: 250px; + overflow-y: scroll; +} diff --git a/admin/images/spinner.gif b/admin/images/spinner.gif new file mode 100644 index 0000000000000000000000000000000000000000..209d10b6bb1a443fa7488d5238b32b93a2bd8b8d GIT binary patch literal 4162 zcmb7{c~nz(7RTQU*$4rX@Q_8Y0fPhxG$1IT)`UQSKs1O50@@G(2?|9D6}6ptBv=-s zhD~rSVaWt!bwveF!jchUJ#1QwQiHZsOHo{=WqRy!UIa%v19j%FoRf2MzPb1J{oL=p zK_Ofp-*^asfad@(Iy!p#^l6z)*4o-SJv}`!F#*Hy>({UCUz@BC+!VoK3j#genMNQ0 z0LWL-d;v8eJ~JNq3|yC;9>0BOVy3sxN)I2V12sD}ozM3RN&7T2K5ctqNWfYLF@fMpbyedV6}^1hHm zLSVBq%QYr|-c5saEsfeK%uZNT7N#!UlgqfE?+8{a03sEoVFkrml^jicAumGXSD8hC zP!XMTz{O{`-E|Ahkul z+e`K|Oh{f7!BQ_6k2V@j2kHK(-XH8&SVKVD`iGWenbKV0aKSjzB1wpDJRPT=%%{{W zzHWs{n|7acrOYQ8^G@=%am+w5i_W1zp_dz_mJMKGBmEg~wDn1O#?xY$16tv!5_Vb} zeW@F7+@53X;}-gHU@%en87Qc!HA;g-=W5Sr-9GxMqOFFXmX6R!IMBGq zb611M=iri>iuUfJJ?AIC-T>yInEiOH-H!D2<&|S}m`=Q8~^1GdbrqFMvR!b}uJ4_1Z+%*UnyGG6 znDlOX_!>g7PKu=qeoI+}3Q!4dq0n{RS-|b|r1gvBr|Im+NOcddS1lm7Wu}?d0L*P! zy&ucZ*=vm$hSj7cVRyo54N8EV-SRW)MKSzvCDRytWeg?ovMS9t7s`=6SYM*Qm~NP ztWm5NGykAw8efT3DtRDmqxXn-_~40GUMH4}s3{VK-7{*_ps7U<-;tVpr0`6EzR#8$ zb%TkhHA$?hg_G)qUT*75E5-RJE)#IZ@CWvm2pC3nHXJLJ=5iw~yZ>7jsjjuXEm*zV znuV6+9BKosj_}5FIOYrswO%j~+XFP;Hr?S1c@_>3tOvrRCA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ZR3}1R zU|jF-83K#JbEsE+9$Zai&e{dW*qpa}J6cG4apcW!MoWPMZ%DUE~*wP|DVw!M4M2#Z{!+J>E;BKgT4tD<_~!zG`6q){Qk@A-_NyIZw7AA#;}JrFOp-;39m$)Q z_BrUitxZTIkkjZ9Xk?C6J+cdD*#^3~F~9ml1{pw@_B&MB&)QURv3PM%>{VMTKcj~z zM-7)PPj;=itoL1=)jWU9&UCXg_)LOugb*{Z#1Ya7(JXTAEq!A=OT@TqHxM>Fj6!x? zq&x%cNCY{U_SP=zG7ny~u2K+>x(F44IsJ{sko;~F?`6i~51w9EhBvE7? zcko!Dc225qo=J6*f^^}6x+8y%oHuV=5n!^ zdpu<-4|v$B^te5db%K}Yct@<9a^@Hm(Q@m_&g`~@5=PgI$1hv1{-3k}aVv~x+`vW{pb&}zwgQ)6UZjMS<@b2)IRsA;VAiT3&P za>EN|qNVrJ!y%TOhs(pIw98kO$whaT0_{g{N-)2e(LT*pU84sj<;cRP%S5^bXrEck zP^2nDPd%`F(D+ojg<&xxAy1e#xN)Ce({vp5^o?WWo(4U`5^uD_N$?vHl$1JdQW1SS zO&<<|YYRPEa6TWGR-F@S>93e)RSTS9GkI$R)*h1N?5hR%AVz(g-{X0*!6O$rQfw{) zZrSH2Daaac@C@B(bSi1h@^W0n#8AF5KHwM+R(D%$~$qP642Fa?ZxFgZaT;!$$`FWX|Or@k#7S$G%0e$O$ce LsoI7F?dpF4ttiU7 literal 0 HcmV?d00001 diff --git a/admin/js/admin-scripts.js b/admin/js/admin-scripts.js new file mode 100644 index 0000000..16ed25f --- /dev/null +++ b/admin/js/admin-scripts.js @@ -0,0 +1,254 @@ +function wpsp_get_taxonomy( type ) { + type = typeof type !== 'undefined' ? type : 'post'; + var response = jQuery.getJSON({ + type: 'POST', + url: ajaxurl, + data: { + action: 'wpsp_get_taxonomies', + wpsp_nonce: wpsp_object.nonce, + post_type: type + }, + async: false, + dataType: 'json' + }); + + return response.responseJSON; +} + +function wpsp_get_terms( type ) { + type = typeof type !== 'undefined' ? type : 'post'; + var response = jQuery.getJSON({ + type: 'POST', + url: ajaxurl, + data: { + action: 'wpsp_get_terms', + wpsp_nonce: wpsp_object.nonce, + taxonomy: type + }, + async: false, + dataType: 'json' + }); + + return response.responseJSON; +} + +function wpsp_get_option( key ) { + key = typeof key !== 'undefined' ? key : 'wpsp_taxonomy'; + var response = jQuery.getJSON({ + type: 'POST', + url: ajaxurl, + data: { + action: 'wpsp_get_json_option', + wpsp_nonce: wpsp_object.nonce, + key: key, + id: wpsp_object.post_id + }, + async: false, + dataType: 'json', + }).done( function() { + jQuery( '#butterbean-control-wpsp_taxonomy' ).css( 'display', 'block' ); + jQuery( '#butterbean-control-wpsp_tax_term' ).css( 'display', 'block' ); + }); + + return response.responseJSON; +} + +jQuery( document ).ready( function( $ ) { + // Populate taxonomy select based on current post type value + var taxonomies = wpsp_get_taxonomy( $( '#wpsp-post-type' ).val() ); + + $('#wpsp-taxonomy').append( $( '' ) ); + $.each(taxonomies, function(key, value) { + $('#wpsp-taxonomy').append( $( '' ).attr( 'value', value ).text( value ) ); + }); + + // Set the selected taxonomy value on load + $( '#wpsp-taxonomy' ).val( wpsp_get_option( 'wpsp_taxonomy' ) ); + + // Show any selected terms + var terms = wpsp_get_terms( $( '#wpsp-taxonomy' ).val() ); + + $.each(terms, function(key, value) { + if ( null !== value ) { + if ( $.isArray( wpsp_get_option( 'wpsp_tax_term' ) ) ) { + var checked = ( $.inArray( value, wpsp_get_option( 'wpsp_tax_term' ) ) > -1 ) ? 'checked="checked"' : ''; + } else { + var checked = ( value === wpsp_get_option( 'wpsp_tax_term' ) ) ? 'checked="checked"' : ''; + } + + $('#butterbean-control-wpsp_tax_term .butterbean-checkbox-list').append( $( '
  • ' ) ); + } + }); + + // Hide the terms of taxonomy is empty on load + if ( '' == $( '#wpsp-taxonomy' ).val() ) { + $( '#butterbean-control-wpsp_tax_term' ).hide(); + } + + // When changing the post type option + $( '#wpsp-post-type' ).change(function() { + + $( '#butterbean-control-wpsp_tax_term' ).hide(); + + $( '#wpsp-taxonomy' ).empty(); + + $( '#wpsp-terms' ).empty(); + $( '#wpsp-terms' ).append( $( '' ) ); + + var selectValues = wpsp_get_taxonomy( $(this).val(), false ); + + $('#wpsp-taxonomy').append( $( '' ) ); + $.each(selectValues, function(key, value) { + $('#wpsp-taxonomy').append( $( '' ).attr( 'value', value ).text( value ) ); + }); + if ( '' == selectValues ) { + $( '#butterbean-control-wpsp_taxonomy' ).hide(); + } else { + $( '#butterbean-control-wpsp_taxonomy' ).show(); + } + }); + + // When changing the taxonomy option + $( '#wpsp-taxonomy' ).change(function() { + + // Empty the list of terms + $( '#butterbean-control-wpsp_tax_term .butterbean-checkbox-list' ).empty(); + + // Get any selected terms + var selectValues = wpsp_get_terms( $(this).val() ); + + // For each selected term, add the checkbox + $.each(selectValues, function(key, value) { + if ( null !== value ) { + $('#butterbean-control-wpsp_tax_term .butterbean-checkbox-list').append( $( '
  • ' ) ); + } + }); + + // Hide the terms area if we don't have any terms + if ( '' == selectValues || ',' == selectValues ) { + $( '#butterbean-control-wpsp_tax_term' ).hide(); + } else { + $( '#butterbean-control-wpsp_tax_term' ).show(); + } + }); + + // Fix color label bug introduced in WP 4.9. + $( '.butterbean-control-color' ).each( function() { + var _this = $( this ); + _this.find( '.wp-picker-input-wrap.hidden .butterbean-label' ).prependTo( _this ); + } ); + + // Dealing with the image options + if ( ! $( '#wpsp-image' ).is( ':checked' ) ) { + $( this ).parent().parent().siblings().hide(); + } + + $( '#wpsp-image' ).change(function() { + if ( ! this.checked ) { + $( this ).parent().parent().siblings().hide(); + } else { + $( this ).parent().parent().siblings().show(); + } + }); + + // Excerpt or full content + $( '#wpsp-content-type' ).change(function() { + if ( 'excerpt' == $( this ).val() ) { + $( '#butterbean-control-wpsp_excerpt_length' ).show(); + } else { + $( '#butterbean-control-wpsp_excerpt_length' ).hide(); + } + }); + + // Title + if ( ! $( '#wpsp-include-title' ).is( ':checked' ) ) { + $( '#butterbean-control-wpsp_title_element' ).hide(); + } + + $( '#wpsp-include-title' ).change(function() { + if ( ! this.checked ) { + $( '#butterbean-control-wpsp_title_element' ).hide(); + } else { + $( '#butterbean-control-wpsp_title_element' ).show(); + } + }); + + // Author location + if ( ! $( '#wpsp-include-author' ).is( ':checked' ) ) { + $( '#butterbean-control-wpsp_author_location' ).hide(); + } + + $( '#wpsp-include-author' ).change(function() { + if ( ! this.checked ) { + $( '#butterbean-control-wpsp_author_location' ).hide(); + } else { + $( '#butterbean-control-wpsp_author_location' ).show(); + } + }); + + // Date location + if ( ! $( '#wpsp-include-date' ).is( ':checked' ) ) { + $( '#butterbean-control-wpsp_date_location' ).hide(); + } + + $( '#wpsp-include-date' ).change(function() { + if ( ! this.checked ) { + $( '#butterbean-control-wpsp_date_location' ).hide(); + } else { + $( '#butterbean-control-wpsp_date_location' ).show(); + } + }); + + // Terms location + if ( ! $( '#wpsp-include-terms' ).is( ':checked' ) ) { + $( '#butterbean-control-wpsp_terms_location' ).hide(); + } + + $( '#wpsp-include-terms' ).change(function() { + if ( ! this.checked ) { + $( '#butterbean-control-wpsp_terms_location' ).hide(); + } else { + $( '#butterbean-control-wpsp_terms_location' ).show(); + } + }); + + // Comments link location + if ( ! $( '#wpsp-include-comments-link' ).is( ':checked' ) ) { + $( '#butterbean-control-wpsp_comments_location' ).hide(); + } + + $( '#wpsp-include-comments-link' ).change(function() { + if ( ! this.checked ) { + $( '#butterbean-control-wpsp_comments_location' ).hide(); + } else { + $( '#butterbean-control-wpsp_comments_location' ).show(); + } + }); + + // Dealing with the social options + $( '#wpsp-social-sharing' ).parent().parent().siblings().hide(); + if ( $( '#wpsp-social-sharing' ).is( ':checked' ) ) { + $( '#wpsp-social-sharing' ).parent().parent().siblings().show(); + } + + $( '#wpsp-social-sharing' ).change(function() { + if ( ! this.checked ) { + $( this ).parent().parent().siblings().hide(); + } else { + $( this ).parent().parent().siblings().show(); + } + }); + + // Pagination + if ( ! $( '#wpsp-pagination' ).is( ':checked' ) ) { + $( '#butterbean-control-wpsp_ajax_pagination' ).hide(); + } + + $( '#wpsp-pagination' ).change(function() { + if ( ! this.checked ) { + $( '#butterbean-control-wpsp_ajax_pagination' ).hide(); + } else { + $( '#butterbean-control-wpsp_ajax_pagination' ).show(); + } + }); +}); diff --git a/admin/js/button.js b/admin/js/button.js new file mode 100644 index 0000000..18266ae --- /dev/null +++ b/admin/js/button.js @@ -0,0 +1,42 @@ +function wpsp_get_post_lists() { + var response = jQuery.getJSON({ + type: 'POST', + url: ajaxurl, + data: { + action: 'wpsp_get_post_lists', + wpsp_nonce: wpsp_nonce + }, + async: false, + dataType: 'json' + }); + + return response.responseJSON; +} + +console.log(wpsp_get_post_lists()); + +(function() { + tinymce.PluginManager.add('wpsp_shortcode_button', function( editor, url ) { + editor.addButton( 'wpsp_shortcode_button', { + title: wpsp_add_posts, + icon: 'wpsp-add-icon', + onclick: function() { + editor.windowManager.open( { + width: 300, + height: 75, + title: wpsp_add_posts, + body: [ + { + type: 'listbox', + name: 'wpsp_add_posts', + label: false, + 'values': wpsp_get_post_lists(), + }], + onsubmit: function( e ) { + editor.insertContent( '[wp_show_posts id="' + e.data.wpsp_add_posts + '"]'); + } + }); + } + }); + }); +})(); \ No newline at end of file diff --git a/admin/metabox.php b/admin/metabox.php new file mode 100644 index 0000000..351a5e4 --- /dev/null +++ b/admin/metabox.php @@ -0,0 +1,993 @@ + $page_boxes ) { + if ( ! empty( $page_boxes ) ) { + foreach( $page_boxes as $context => $box_context ) { + if ( ! empty( $box_context ) ) { + foreach( $box_context as $box_type ) { + if ( ! empty( $box_type ) ) { + foreach( $box_type as $id => $box ) { + /** Check to see if the meta box should be removed... */ + if ( ! in_array( $id, $exceptions ) ) { + remove_meta_box( $id, $page, $context ); + } + } + } + } + } + } + } + } + } + } +} + +if ( ! function_exists( 'wpsp_get_post_types' ) ) { + /** + * List of all our post types exluding our own + * @since 0.1 + */ + function wpsp_get_post_types() { + $post_types = get_post_types( array( 'public' => true ) ); + $types = array(); + foreach ( $post_types as $type ) { + if ( 'wp_show_posts' !== $type && 'attachment' !== $type ) { + $types[ $type ] = $type; + } + } + + return $types; + } +} + +if ( ! function_exists( 'wpsp_load_butterbean' ) ) { + add_action( 'plugins_loaded', 'wpsp_load_butterbean' ); + /** + * Load butterbean inside our post type + * @since 0.1 + */ + function wpsp_load_butterbean() { + require_once( trailingslashit( dirname( __FILE__ ) ) . '/butterbean/butterbean.php' ); + } +} + +if ( ! function_exists( 'wpsp_register' ) ) { + add_action( 'butterbean_register', 'wpsp_register', 10, 2 ); + /** + * Create all of our metabox options + * @since 0.1 + */ + function wpsp_register( $butterbean, $post_type ) { + + $defaults = wpsp_get_defaults(); + + // Register managers, sections, controls, and settings here. + $butterbean->register_manager( + 'wp_show_posts', + array( + 'label' => esc_html__( 'WP Show Posts', 'wp-show-posts' ), + 'post_type' => 'wp_show_posts', + 'context' => 'normal', + 'priority' => 'high' + ) + ); + + $manager = $butterbean->get_manager( 'wp_show_posts' ); + + $manager->register_section( + 'wpsp_posts', + array( + 'label' => esc_html__( 'Posts', 'wp-show-posts' ), + 'icon' => 'dashicons-admin-post' + ) + ); + + $manager->register_control( + 'wpsp_post_type', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_posts', + 'label' => esc_html__( 'Post type', 'wp-show-posts' ), + 'choices' => wpsp_get_post_types(), + 'attr' => array( 'id' => 'wpsp-post-type' ) + ) + ); + + $manager->register_setting( + 'wpsp_post_type', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_post_type' ] ? $defaults[ 'wpsp_post_type' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_taxonomy', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_posts', + 'label' => esc_html__( 'Taxonomy', 'wp-show-posts' ), + 'choices' => array(), + 'attr' => array( 'id' => 'wpsp-taxonomy' ) + ) + ); + + $manager->register_setting( + 'wpsp_taxonomy', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_taxonomy' ] ? $defaults[ 'wpsp_taxonomy' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_tax_term', // Same as setting name. + array( + 'type' => 'checkboxes', + 'section' => 'wpsp_posts', + 'label' => esc_html__( 'Terms', 'wp-show-posts' ), + 'choices' => array(), + ) + ); + + $manager->register_setting( + 'wpsp_tax_term', // Same as control name. + array( + 'sanitize_callback' => '', + 'default' => $defaults[ 'wpsp_tax_term' ] ? $defaults[ 'wpsp_tax_term' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_posts_per_page', // Same as setting name. + array( + 'type' => 'number', + 'section' => 'wpsp_posts', + 'label' => esc_html__( 'Posts per page', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_posts_per_page', // Same as control name. + array( + 'sanitize_callback' => 'wpsp_sanitize_intval', + 'default' => $defaults[ 'wpsp_posts_per_page' ] ? $defaults[ 'wpsp_posts_per_page' ] : 10 + ) + ); + + $manager->register_control( + 'wpsp_pagination', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_posts', + 'label' => __( 'Pagination','wp-show-posts' ), + 'description' => __( 'Pagination should only be used if your posts are the only thing in the content area to prevent duplicate content issues.','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-pagination' ) + ) + ); + + $manager->register_setting( + 'wpsp_pagination', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_pagination' ] ? $defaults[ 'wpsp_pagination' ] : false + ) + ); + + $manager->register_section( + 'wpsp_columns', + array( + 'label' => esc_html__( 'Columns', 'wp-show-posts' ), + 'icon' => 'dashicons-grid-view' + ) + ); + + $manager->register_control( + 'wpsp_columns', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_columns', + 'label' => esc_html__( 'Columns', 'wp-show-posts' ), + 'choices' => array( + 'col-12' => '1', + 'col-6' => '2', + 'col-4' => '3', + 'col-3' => '4', + 'col-20' => '5' + ), + 'attr' => array( 'id' => 'wpsp-columns' ) + ) + ); + + $manager->register_setting( + 'wpsp_columns', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_columns' ] ? $defaults[ 'wpsp_columns' ] : '12' + ) + ); + + $manager->register_control( + 'wpsp_columns_gutter', // Same as setting name. + array( + 'type' => 'text', + 'section' => 'wpsp_columns', + 'label' => esc_html__( 'Columns gutter', 'wp-show-posts' ), + 'attr' => array( 'class' => 'widefat' ), + ) + ); + + $manager->register_setting( + 'wpsp_columns_gutter', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_columns_gutter' ] ? $defaults[ 'wpsp_columns_gutter' ] : '' + ) + ); + + $manager->register_section( + 'wpsp_images', + array( + 'label' => esc_html__( 'Images', 'wp-show-posts' ), + 'icon' => 'dashicons-format-image' + ) + ); + + $manager->register_control( + 'wpsp_image', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_images', + 'label' => __( 'Images','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-image' ) + ) + ); + + $manager->register_setting( + 'wpsp_image', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_image' ] + ) + ); + + $manager->register_control( + 'wpsp_image_width', // Same as setting name. + array( + 'type' => 'number', + 'section' => 'wpsp_images', + 'label' => esc_html__( 'Image width (px)', 'wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-image-width' ) + ) + ); + + $manager->register_setting( + 'wpsp_image_width', // Same as control name. + array( + 'sanitize_callback' => 'wpsp_sanitize_absint', + 'default' => $defaults[ 'wpsp_image_width' ] ? $defaults[ 'wpsp_image_width' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_image_height', // Same as setting name. + array( + 'type' => 'number', + 'section' => 'wpsp_images', + 'label' => esc_html__( 'Image height (px)', 'wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-image-height' ) + ) + ); + + $manager->register_setting( + 'wpsp_image_height', // Same as control name. + array( + 'sanitize_callback' => 'wpsp_sanitize_absint', + 'default' => $defaults[ 'wpsp_image_height' ] ? $defaults[ 'wpsp_image_height' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_image_alignment', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_images', + 'label' => esc_html__( 'Image alignment', 'wp-show-posts' ), + 'choices' => array( + 'left' => __( 'Left','wp-show-posts' ), + 'center' => __( 'Center','wp-show-posts' ), + 'right' => __( 'Right','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-image-alignment' ) + ) + ); + + $manager->register_setting( + 'wpsp_image_alignment', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_image_alignment' ] ? $defaults[ 'wpsp_image_alignment' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_image_location', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_images', + 'label' => esc_html__( 'Image location', 'wp-show-posts' ), + 'choices' => array( + 'below-title' => __( 'Below title','wp-show-posts' ), + 'above-title' => __( 'Above title','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-image-location' ) + ) + ); + + $manager->register_setting( + 'wpsp_image_location', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_image_location' ] ? $defaults[ 'wpsp_image_location' ] : '' + ) + ); + + $manager->register_section( + 'wpsp_content', + array( + 'label' => esc_html__( 'Content', 'wp-show-posts' ), + 'icon' => 'dashicons-editor-alignleft' + ) + ); + + $manager->register_control( + 'wpsp_content_type', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_content', + 'label' => esc_html__( 'Content type', 'wp-show-posts' ), + 'choices' => array( + 'excerpt' => __( 'Excerpt','wp-show-posts' ), + 'full' => __( 'Full','wp-show-posts' ), + 'none' => __( 'None','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-content-type' ) + ) + ); + + $manager->register_setting( + 'wpsp_content_type', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_content_type' ] ? $defaults[ 'wpsp_content_type' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_list_type', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_content', + 'label' => esc_html__( 'List type', 'wp-show-posts' ), + 'choices' => array( + 'ordered' => __( 'Ordered','wp-show-posts' ), + 'unordered' => __( 'Unordered','wp-show-posts' ), + 'none' => __( 'None','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-list-type' ) + ) + ); + + $manager->register_setting( + 'wpsp_list_type', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_list_type' ] ? $defaults[ 'wpsp_list_type' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_excerpt_length', // Same as setting name. + array( + 'type' => 'number', + 'section' => 'wpsp_content', + 'label' => esc_html__( 'Excerpt length (words)', 'wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-excerpt-length' ) + ) + ); + + $manager->register_setting( + 'wpsp_excerpt_length', // Same as control name. + array( + 'sanitize_callback' => 'wpsp_sanitize_absint', + 'default' => $defaults[ 'wpsp_excerpt_length' ] ? $defaults[ 'wpsp_excerpt_length' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_include_title', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_content', + 'label' => __( 'Include title','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-include-title' ) + ) + ); + + $manager->register_setting( + 'wpsp_include_title', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => true + ) + ); + + // Title element + $manager->register_control( + 'wpsp_title_element', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_content', + 'label' => esc_html__( 'Title element', 'wp-show-posts-pro' ), + 'choices' => array( + '' => '', + 'p' => 'p', + 'span' => 'span', + 'h1' => 'h1', + 'h2' => 'h2', + 'h3' => 'h3', + 'h4' => 'h4', + 'h5' => 'h5' + ), + 'attr' => array( 'id' => 'wpsp-title-element' ) + ) + ); + + $manager->register_setting( + 'wpsp_title_element', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_title_element' ] ? $defaults[ 'wpsp_title_element' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_read_more_text', // Same as setting name. + array( + 'type' => 'text', + 'section' => 'wpsp_content', + 'label' => esc_html__( 'Read more text', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_read_more_text', // Same as control name. + array( + 'sanitize_callback' => 'wp_kses_post', + 'default' => $defaults[ 'wpsp_read_more_text' ] ? $defaults[ 'wpsp_read_more_text' ] : '' + ) + ); + + $manager->register_section( + 'wpsp_post_meta', + array( + 'label' => esc_html__( 'Meta', 'wp-show-posts' ), + 'icon' => 'dashicons-editor-ul' + ) + ); + + $manager->register_control( + 'wpsp_include_author', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_post_meta', + 'label' => __( 'Include author','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-include-author' ) + ) + ); + + $manager->register_setting( + 'wpsp_include_author', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_include_author' ] ? $defaults[ 'wpsp_include_author' ] : false + ) + ); + + $manager->register_control( + 'wpsp_author_location', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_post_meta', + 'label' => esc_html__( 'Author location', 'wp-show-posts' ), + 'choices' => array( + 'below-title' => __( 'Below title','wp-show-posts' ), + 'below-post' => __( 'Below post','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-author-location' ) + ) + ); + + $manager->register_setting( + 'wpsp_author_location', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_author_location' ] ? $defaults[ 'wpsp_author_location' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_include_date', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_post_meta', + 'label' => __( 'Include date','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-include-date' ) + ) + ); + + $manager->register_setting( + 'wpsp_include_date', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_include_date' ] ? $defaults[ 'wpsp_include_date' ] : false + ) + ); + + $manager->register_control( + 'wpsp_date_location', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_post_meta', + 'label' => esc_html__( 'Date location', 'wp-show-posts' ), + 'choices' => array( + 'below-title' => __( 'Below title','wp-show-posts' ), + 'below-post' => __( 'Below post','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-date-location' ) + ) + ); + + $manager->register_setting( + 'wpsp_date_location', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_date_location' ] ? $defaults[ 'wpsp_date_location' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_include_terms', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_post_meta', + 'label' => __( 'Include terms','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-include-terms' ) + ) + ); + + $manager->register_setting( + 'wpsp_include_terms', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_include_terms' ] ? $defaults[ 'wpsp_include_terms' ] : false + ) + ); + + $manager->register_control( + 'wpsp_terms_location', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_post_meta', + 'label' => esc_html__( 'Terms location', 'wp-show-posts' ), + 'choices' => array( + 'below-title' => __( 'Below title','wp-show-posts' ), + 'below-post' => __( 'Below post','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-terms-location' ) + ) + ); + + $manager->register_setting( + 'wpsp_terms_location', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_terms_location' ] ? $defaults[ 'wpsp_terms_location' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_include_comments', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_post_meta', + 'label' => __( 'Include comments link','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-include-comments-link' ) + ) + ); + + $manager->register_setting( + 'wpsp_include_comments', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_include_comments' ] ? $defaults[ 'wpsp_include_comments' ] : false + ) + ); + + $manager->register_control( + 'wpsp_comments_location', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_post_meta', + 'label' => esc_html__( 'Comments link location', 'wp-show-posts' ), + 'choices' => array( + 'below-title' => __( 'Below title','wp-show-posts' ), + 'below-post' => __( 'Below post','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-comments-link-location' ) + ) + ); + + $manager->register_setting( + 'wpsp_comments_location', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_comments_location' ] ? $defaults[ 'wpsp_comments_location' ] : '' + ) + ); + + $manager->register_section( + 'wpsp_query_args', + array( + 'label' => esc_html__( 'More settings', 'wp-show-posts' ), + 'icon' => 'dashicons-admin-generic', + 'priority' => 999 + ) + ); + + $manager->register_control( + 'wpsp_author', // Same as setting name. + array( + 'type' => 'number', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'Author ID', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_author', // Same as control name. + array( + 'sanitize_callback' => 'wpsp_sanitize_absint', + 'default' => $defaults[ 'wpsp_author' ] ? $defaults[ 'wpsp_author' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_exclude_current', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_query_args', + 'label' => __( 'Exclude current','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-exclude-current' ) + ) + ); + + $manager->register_setting( + 'wpsp_exclude_current', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_exclude_current' ] ? $defaults[ 'wpsp_exclude_current' ] : false + ) + ); + + $manager->register_control( + 'wpsp_post_id', // Same as setting name. + array( + 'type' => 'text', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'Post IDs', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_post_id', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_post_id' ] ? $defaults[ 'wpsp_post_id' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_exclude_post_id', // Same as setting name. + array( + 'type' => 'text', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'Exclude Post IDs', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_exclude_post_id', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_exclude_post_id' ] ? $defaults[ 'wpsp_exclude_post_id' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_ignore_sticky_posts', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_query_args', + 'label' => __( 'Ignore sticky posts','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-ignore-sticky-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_ignore_sticky_posts', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_ignore_sticky_posts' ] ? $defaults[ 'wpsp_ignore_sticky_posts' ] : false + ) + ); + + $manager->register_control( + 'wpsp_offset', // Same as setting name. + array( + 'type' => 'number', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'Offset', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_offset', // Same as control name. + array( + 'sanitize_callback' => 'wpsp_sanitize_absint', + 'default' => $defaults[ 'wpsp_offset' ] ? $defaults[ 'wpsp_offset' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_order', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'Order', 'wp-show-posts' ), + 'choices' => array( + 'DESC' => __( 'Descending','wp-show-posts' ), + 'ASC' => __( 'Ascending','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-order' ) + ) + ); + + $manager->register_setting( + 'wpsp_order', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_order' ] ? $defaults[ 'wpsp_order' ] : 'DESC' + ) + ); + + $manager->register_control( + 'wpsp_orderby', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'Order by', 'wp-show-posts' ), + 'choices' => array( + 'none' => __( 'No order','wp-show-posts' ), + 'ID' => __( 'ID','wp-show-posts' ), + 'author' => __( 'Author','wp-show-posts' ), + 'title' => __( 'Title','wp-show-posts' ), + 'name' => __( 'Slug','wp-show-posts' ), + 'type' => __( 'Post type','wp-show-posts' ), + 'date' => __( 'Date','wp-show-posts' ), + 'modified' => __( 'Modified','wp-show-posts' ), + 'parent' => __( 'Parent','wp-show-posts' ), + 'rand' => __( 'Random','wp-show-posts' ), + 'comment_count' => __( 'Comment count','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-orderby' ) + ) + ); + + $manager->register_setting( + 'wpsp_orderby', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_orderby' ] ? $defaults[ 'wpsp_orderby' ] : 'date' + ) + ); + + $manager->register_control( + 'wpsp_post_status', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'Status', 'wp-show-posts' ), + 'choices' => array( + 'publish' => __( 'Published','wp-show-posts' ), + 'pending' => __( 'Pending','wp-show-posts' ), + 'draft' => __( 'Draft','wp-show-posts' ), + 'auto-draft' => __( 'Auto draft','wp-show-posts' ), + 'future' => __( 'Future','wp-show-posts' ), + 'private' => __( 'Private','wp-show-posts' ), + 'inherit' => __( 'Inherit','wp-show-posts' ), + 'trash' => __( 'Trash','wp-show-posts' ), + 'any' => __( 'Any','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-post-status' ) + ) + ); + + $manager->register_setting( + 'wpsp_post_status', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_post_status' ] ? $defaults[ 'wpsp_post_status' ] : 'publish' + ) + ); + + $manager->register_control( + 'wpsp_meta_key', // Same as setting name. + array( + 'type' => 'text', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'Meta key', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_meta_key', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_meta_key' ] ? $defaults[ 'wpsp_meta_key' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_meta_value', // Same as setting name. + array( + 'type' => 'text', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'Meta value', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_meta_value', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_meta_value' ] ? $defaults[ 'wpsp_meta_value' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_tax_operator', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'Tax operator', 'wp-show-posts' ), + 'choices' => array( + 'IN' => 'IN', + 'NOT IN' => 'NOT IN', + 'AND' => 'AND', + 'EXISTS' => 'EXISTS', + 'NOT EXISTS' => 'NOT EXISTS' + ), + 'attr' => array( 'id' => 'wpsp-tax-operator' ) + ) + ); + + $manager->register_setting( + 'wpsp_tax_operator', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_tax_operator' ] ? $defaults[ 'wpsp_tax_operator' ] : 'IN' + ) + ); + + $manager->register_control( + 'wpsp_no_results', // Same as setting name. + array( + 'type' => 'text', + 'section' => 'wpsp_query_args', + 'label' => esc_html__( 'No results message', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_no_results', // Same as control name. + array( + 'sanitize_callback' => 'wp_kses_post', + 'default' => $defaults[ 'wpsp_no_results' ] ? $defaults[ 'wpsp_no_results' ] : '' + ) + ); + } +} + +if ( ! function_exists( 'wpsp_sanitize_intval' ) ) { + /** + * Sanitize our value so it has to be a positive integer + * @since 0.1 + */ + function wpsp_sanitize_intval( $input ) { + if ( '' == $input ) { + return $input; + } + + return intval( $input ); + } +} + +if ( ! function_exists( 'wpsp_sanitize_absint' ) ) { + /** + * Sanitize our value so it can be a negative or positive integer + * @since 0.1 + */ + function wpsp_sanitize_absint( $input ) { + if ( '' == $input ) { + return $input; + } + + return absint( $input ); + } +} + +if ( ! function_exists( 'wpsp_add_meta_boxes' ) ) { + add_action( 'add_meta_boxes_wp_show_posts', 'wpsp_add_meta_boxes' ); + /** + * Add our usage metabox + * @since 0.1 + */ + function wpsp_add_meta_boxes( $post ){ + add_meta_box( 'wpsp_shortcode', __( 'Usage', 'wp-show-posts' ), 'wpsp_shortcode_metabox', 'wp_show_posts', 'side', 'low' ); + } +} + +if ( ! function_exists( 'wpsp_shortcode_metabox' ) ) { + /** + * Meta box display callback. + * + * @param WP_Post $post Current post object. + * @since 0.1 + */ + function wpsp_shortcode_metabox( $post ) { + ?> +

    + + +

    + ID . " ); ?>" ); ?>' readonly /> + _x( 'Post Lists', 'Post Type General Name', 'wp-show-posts' ), + 'singular_name' => _x( 'Post List', 'Post Type Singular Name', 'wp-show-posts' ), + 'menu_name' => __( 'WP Show Posts', 'wp-show-posts' ), + 'name_admin_bar' => __( 'WP Show Posts', 'wp-show-posts' ), + 'archives' => __( 'List Archives', 'wp-show-posts' ), + 'parent_item_colon' => __( 'Parent List:', 'wp-show-posts' ), + 'all_items' => __( 'All Lists', 'wp-show-posts' ), + 'add_new_item' => __( 'Add New List', 'wp-show-posts' ), + 'add_new' => __( 'Add New', 'wp-show-posts' ), + 'new_item' => __( 'New List', 'wp-show-posts' ), + 'edit_item' => __( 'Edit List', 'wp-show-posts' ), + 'update_item' => __( 'Update List', 'wp-show-posts' ), + 'view_item' => __( 'View List', 'wp-show-posts' ), + 'search_items' => __( 'Search List', 'wp-show-posts' ), + 'not_found' => __( 'Not found', 'wp-show-posts' ), + 'not_found_in_trash' => __( 'Not found in Trash', 'wp-show-posts' ), + 'featured_image' => __( 'Featured Image', 'wp-show-posts' ), + 'set_featured_image' => __( 'Set featured image', 'wp-show-posts' ), + 'remove_featured_image' => __( 'Remove featured image', 'wp-show-posts' ), + 'use_featured_image' => __( 'Use as featured image', 'wp-show-posts' ), + 'insert_into_item' => __( 'Insert into list', 'wp-show-posts' ), + 'uploaded_to_this_item' => __( 'Uploaded to this list', 'wp-show-posts' ), + 'items_list' => __( 'Items list', 'wp-show-posts' ), + 'items_list_navigation' => __( 'Items list navigation', 'wp-show-posts' ), + 'filter_items_list' => __( 'Filter items list', 'wp-show-posts' ), + ); + $args = array( + 'label' => __( 'Post List', 'wp-show-posts' ), + 'labels' => $labels, + 'supports' => array( 'title' ), + 'hierarchical' => false, + 'public' => false, + 'show_ui' => true, + 'show_in_menu' => true, + 'menu_position' => 5, + 'show_in_admin_bar' => false, + 'show_in_nav_menus' => false, + 'can_export' => true, + 'has_archive' => false, + 'exclude_from_search' => true, + 'publicly_queryable' => false, + 'capability_type' => 'page', + ); + register_post_type( 'wp_show_posts', $args ); + + } +} diff --git a/admin/widget.php b/admin/widget.php new file mode 100644 index 0000000..dc24b2a --- /dev/null +++ b/admin/widget.php @@ -0,0 +1,112 @@ + +

    + + +

    +

    + +

    + '', + 'wpsp_author_location' => 'below-post', + 'wpsp_columns' => 'col-6', + 'wpsp_columns_gutter' => '2em', + 'wpsp_content_type' => 'excerpt', + 'wpsp_list_type' => 'none', + 'wpsp_date_location' => 'below-title', + 'wpsp_exclude_current' => false, + 'wpsp_excerpt_length' => 30, + 'wpsp_post_id' => '', + 'wpsp_exclude_post_id' => '', + 'wpsp_ignore_sticky_posts' => false, + 'wpsp_image' => true, + 'wpsp_image_alignment' => 'center', + 'wpsp_image_height' => '', + 'wpsp_image_location' => 'below-title', + 'wpsp_image_width' => '', + 'wpsp_include_title' => true, + 'wpsp_title_element' => 'h2', + 'wpsp_include_terms' => false, + 'wpsp_include_author' => false, + 'wpsp_include_date' => true, + 'wpsp_include_comments' => false, + 'wpsp_comments_location' => 'below-post', + 'wpsp_inner_wrapper' => 'article', + 'wpsp_inner_wrapper_class' => '', + 'wpsp_inner_wrapper_style' => '', + 'wpsp_itemtype' => 'CreativeWork', + 'wpsp_meta_key' => '', + 'wpsp_meta_value' => '', + 'wpsp_offset' => 0, + 'wpsp_order' => 'DESC', + 'wpsp_orderby' => 'date', + 'wpsp_pagination' => false, + 'wpsp_post_meta_bottom_style' => 'stack', + 'wpsp_post_meta_top_style' => 'inline', + 'wpsp_post_status' => 'publish', + 'wpsp_post_type' => 'post', + 'wpsp_posts_per_page' => 10, + 'wpsp_read_more_text' => '', + 'wpsp_tax_operator' => 'IN', + 'wpsp_tax_term' => '', + 'wpsp_taxonomy' => 'category', + 'wpsp_terms_location' => 'below-post', + 'wpsp_wrapper' => 'section', + 'wpsp_wrapper_class' => '', + 'wpsp_wrapper_id' => false, + 'wpsp_wrapper_style' => '', + 'wpsp_no_results' => __( 'Sorry, no posts were found.','wp-show-posts' ) + ); + + return apply_filters( 'wpsp_defaults', $defaults ); + } +} diff --git a/inc/deprecated.php b/inc/deprecated.php new file mode 100644 index 0000000..e0ecb82 --- /dev/null +++ b/inc/deprecated.php @@ -0,0 +1,10 @@ +'; + } + + // If our author is enabled, show it + if ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) { + $output[] = apply_filters( 'wpsp_author_output', sprintf( + '', + esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), + esc_attr( sprintf( __( 'View all posts by %s', 'wp-show-posts' ), get_the_author() ) ), + esc_html( get_the_author() ) + ) ); + } + + // Show the date + if ( $settings[ 'include_date' ] && $location == $settings[ 'date_location' ] ) { + $time_string = ''; + + if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { + $time_string .= ''; + } + + $time_string = sprintf( $time_string, + esc_attr( get_the_date( 'c' ) ), + esc_html( get_the_date() ), + esc_attr( get_the_modified_date( 'c' ) ), + esc_html( get_the_modified_date() ) + ); + + // If our date is enabled, show it + $output[] = apply_filters( 'wpsp_date_output', sprintf( + ' + %3$s + ', + esc_url( get_permalink() ), + esc_attr( get_the_time() ), + $time_string + ) ); + } + + // Show the terms + if ( $settings[ 'include_terms' ] && $location == $settings[ 'terms_location' ] ) { + $output[] = apply_filters( 'wpsp_terms_output', sprintf( '%1$s', + get_the_term_list( get_the_ID(), $settings[ 'taxonomy' ], '', apply_filters( 'wpsp_term_separator', ', ' ) ) + ) ); + } + + if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) && ( $settings[ 'include_comments' ] && $location == $settings[ 'comments_location' ] ) ) { + ob_start(); + echo ''; + comments_popup_link( __( 'Leave a comment', 'wp-show-posts' ), __( '1 Comment', 'wp-show-posts' ), __( '% Comments', 'wp-show-posts' ) ); + echo ''; + $comments_link = ob_get_clean(); + $output[] = $comments_link; + } + + // Set up our separator + $separator = ( 'inline' == $post_meta_style ) ? ' | ' : '
    '; + + // Echo our output + echo implode( $separator, $output); + + if ( ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && $location == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && $location == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && $location == $settings[ 'comments_location' ] ) ) { + echo ''; + } + } +} + +if ( ! function_exists( 'wpsp_add_post_meta_after_title' ) ) { + add_action( 'wpsp_after_title','wpsp_add_post_meta_after_title' ); + function wpsp_add_post_meta_after_title( $settings ) { + if ( ( $settings[ 'include_author' ] && 'below-title' == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && 'below-title' == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && 'below-title' == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && 'below-title' == $settings[ 'comments_location' ] ) ) { + wpsp_meta( 'below-title', $settings ); + } + + } +} + +if ( ! function_exists( 'wpsp_add_post_meta_after_content' ) ) { + add_action( 'wpsp_after_content','wpsp_add_post_meta_after_content', 10 ); + function wpsp_add_post_meta_after_content( $settings ) { + if ( ( $settings[ 'include_author' ] && 'below-post' == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && 'below-post' == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && 'below-post' == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && 'below-post' == $settings[ 'comments_location' ] ) ) { + wpsp_meta( 'below-post', $settings ); + } + } +} + +if ( ! function_exists( 'wpsp_post_image' ) ) { + /** + * Build our post image + * @since 0.1 + */ + function wpsp_post_image( $settings ) { + if ( ! has_post_thumbnail() ) { + return; + } + + if ( ! isset( $settings[ 'image' ] ) || ! $settings[ 'image' ] ) { + return; + } + + $image_id = get_post_thumbnail_id( get_the_ID(), 'full' ); + $image_url = wp_get_attachment_image_src( $image_id, 'full', true ); + $image_atts = wpsp_image_attributes( $image_url[1], $image_url[2], $settings[ 'image_width' ], $settings[ 'image_height' ] ); + + // Set pro settings for old versions of WPSP Pro. + if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) { + $settings[ 'image_overlay_color' ] = wpsp_sanitize_hex_color( wpsp_get_setting( $settings['list_id'], 'wpsp_image_overlay_color' ) ); + $settings[ 'image_overlay_icon' ] = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_image_overlay_icon' ) ); + $hover = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_image_hover_effect' ) ); + } else { + $hover = ( isset( $settings[ 'image_hover_effect' ] ) && '' !== $settings[ 'image_hover_effect' ] ) ? $settings[ 'image_hover_effect' ] : ''; + } + + $disable_link = apply_filters( 'wpsp_disable_image_link', false, $settings ); + ?> +
    + ', + esc_url( apply_filters( 'wpsp_image_href', get_the_permalink(), $settings ) ), + apply_filters( 'wpsp_image_data', '', $settings ), + esc_attr( apply_filters( 'wpsp_image_title', the_title_attribute( 'echo=0' ), $settings ) ) + ); + } + + if ( ! empty( $image_atts ) ) : ?> + <?php esc_attr( the_title() ); ?> + 'image' ) ); + endif; + + if ( isset( $settings[ 'image_overlay_color' ] ) && ( '' !== $settings[ 'image_overlay_color' ] || '' !== $settings[ 'image_overlay_icon' ] ) ) { + $color = ( $settings[ 'image_overlay_color' ] ) ? 'style="background-color:' . wpsp_hex2rgba( $settings[ 'image_overlay_color' ], apply_filters( 'wpsp_overlay_opacity', 0.7 ) ) . '"' : ''; + $icon = ( $settings[ 'image_overlay_icon' ] ) ? $settings[ 'image_overlay_icon' ] : 'no-icon'; + echo ''; + } + + if ( ! $disable_link ) { + echo ''; + } + ?> +
    + %3$s', + the_title_attribute( 'echo=0' ), + esc_url( get_permalink() ), + $settings[ 'read_more_text' ] + )); + } + } +} + +if ( ! function_exists( 'wpsp_hex2rgba' ) ) { + /** + * Convert hex to RGBA + * @since 0.1 + */ + function wpsp_hex2rgba($color, $opacity = false) { + + $default = 'rgb(0,0,0)'; + + // Return default if no color provided + if ( empty( $color ) ) { + return $default; + } + + // Sanitize $color if "#" is provided + if ($color[0] == '#' ) { + $color = substr( $color, 1 ); + } + + // Check if color has 6 or 3 characters and get values + if ( strlen( $color ) == 6) { + $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); + } elseif ( strlen( $color ) == 3 ) { + $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); + } else { + return $default; + } + + // Convert hexadec to rgb + $rgb = array_map('hexdec', $hex); + + // Check if opacity is set(rgba or rgb) + if ( $opacity ){ + if( abs( $opacity ) > 1) { + $opacity = 1.0; + } + $output = 'rgba('.implode(",",$rgb).','.$opacity.')'; + } else { + $output = 'rgb('.implode(",",$rgb).')'; + } + + // Return rgb(a) color string + return $output; + } +} + +if ( ! function_exists( 'wpsp_sanitize_hex_color' ) ) { + function wpsp_sanitize_hex_color( $color ) { + if ( '' === $color ) { + return ''; + } + + // 3 or 6 hex digits, or the empty string. + if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) { + return $color; + } + } +} + +if ( ! function_exists( 'wpsp_image_attributes' ) ) { + /** + * Build our image attributes + * @since 0.1 + */ + function wpsp_image_attributes( $og_width = '', $og_height = '', $new_width = '', $new_height = '' ) { + $ignore_crop = array( '', '0', '9999' ); + + $image_atts = array( + 'width' => ( in_array( $new_width, $ignore_crop ) ) ? 9999 : intval( $new_width ), + 'height' => ( in_array( $new_height, $ignore_crop ) ) ? 9999 : intval( $new_height ), + 'crop' => ( in_array( $new_width, $ignore_crop ) || in_array( $new_height, $ignore_crop ) ) ? false : true + ); + + // If there's no height or width, empty the array + if ( 9999 == $image_atts[ 'width' ] && 9999 == $image_atts[ 'height' ] ) { + $image_atts = array(); + } + + if ( ! empty( $image_atts ) ) { + // Is our width larger than the OG image and not proportional? + $width_upscale = $image_atts[ 'width' ] > $og_width && $image_atts[ 'width' ] < 9999 ? true : false; + + // Is our height larger than the OG image and not proportional? + $height_upscale = $image_atts[ 'height' ] > $og_height && $image_atts[ 'height' ] < 9999 ? true : false; + + // If both the height and width are larger than the OG image, upscale + $image_atts[ 'upscale' ] = $width_upscale && $height_upscale ? true : false; + + // If the width is larger than the OG image and the height isn't proportional, upscale + $image_atts[ 'upscale' ] = $width_upscale && $image_atts[ 'height' ] < 9999 ? true : $image_atts[ 'upscale' ]; + + // If the height is larger than the OG image and width isn't proportional, upscale + $image_atts[ 'upscale' ] = $height_upscale && $image_atts[ 'width' ] < 9999 ? true : $image_atts[ 'upscale' ]; + + // If we're upscaling, set crop to true + $image_atts[ 'crop' ] = $image_atts[ 'upscale' ] ? true : $image_atts[ 'crop' ]; + + // If one of our sizes is upscaling but the other is proportional, show the full image + if ( $width_upscale && $image_atts[ 'height' ] == 9999 || $height_upscale && $image_atts[ 'width' ] == 9999 ) { + $image_atts = array(); + } + } + + return apply_filters( 'wpsp_image_attributes', $image_atts ); + } +} + +if ( ! function_exists( 'wpsp_pagination' ) ) { + /** + * Build our regular pagination + * @since 0.1 + */ + function wpsp_pagination( $max_num_pages ) { + // Don't print empty markup if there's only one page. + if ( $max_num_pages < 2 ) { + return; + } + + $paged_query = is_front_page() ? 'page' : 'paged'; + $paged = get_query_var( $paged_query ) ? intval( get_query_var( $paged_query ) ) : 1; + $pagenum_link = html_entity_decode( get_pagenum_link() ); + $query_args = array(); + $url_parts = explode( '?', $pagenum_link ); + + if ( isset( $url_parts[1] ) ) { + wp_parse_str( $url_parts[1], $query_args ); + } + + $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link ); + $pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; + + $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; + $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%'; + + // Set up paginated links. + $links = paginate_links( array( + 'base' => $pagenum_link, + 'format' => $format, + 'total' => $max_num_pages, + 'current' => $paged, + 'mid_size' => apply_filters( 'wpsp_pagination_mid_size', 1 ), + 'add_args' => array_map( 'urlencode', $query_args ), + 'prev_text' => __( '← Previous', 'wp-show-posts' ), + 'next_text' => __( 'Next →', 'wp-show-posts' ), + ) ); + + if ( $links ) { + echo '
    ' . $links . '
    '; + } + } +} diff --git a/inc/image-resizer.php b/inc/image-resizer.php new file mode 100644 index 0000000..e62c16c --- /dev/null +++ b/inc/image-resizer.php @@ -0,0 +1,244 @@ + "$http_prefix", 1 => "$https_prefix"),$relative_prefix,$upload_url); + } + + + // Check if $img_url is local. + if ( false === strpos( $url, $upload_url ) ) + throw new WPSP_Exception('Image must be local: ' . $url); + + // Define path of image. + $rel_path = str_replace( $upload_url, '', $url ); + $img_path = $upload_dir . $rel_path; + + // Check if img path exists, and is an image indeed. + if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) ) + throw new WPSP_Exception('Image file does not exist (or is not an image): ' . $img_path); + + // Get image info. + $info = pathinfo( $img_path ); + $ext = $info['extension']; + list( $orig_w, $orig_h ) = getimagesize( $img_path ); + + // Get image size after cropping. + $dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop ); + $dst_w = $dims[4]; + $dst_h = $dims[5]; + + // Return the original image only if it exactly fits the needed measures. + if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) { + $img_url = $url; + $dst_w = $orig_w; + $dst_h = $orig_h; + } else { + // Use this to check if cropped image already exists, so we can return that instead. + $suffix = "{$dst_w}x{$dst_h}"; + $dst_rel_path = str_replace( '.' . $ext, '', $rel_path ); + $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}"; + + if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) { + // Can't resize, so return false saying that the action to do could not be processed as planned. + throw new WPSP_Exception('Unable to resize image because image_resize_dimensions() failed'); + } + // Else check if cache exists. + elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) { + $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}"; + } + // Else, we resize the image and return the new resized image url. + else { + + $editor = wp_get_image_editor( $img_path ); + + if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) { + throw new WPSP_Exception('Unable to get WP_Image_Editor: ' . + $editor->get_error_message() . ' (is GD or ImageMagick installed?)'); + } + + $resized_file = $editor->save(); + + if ( ! is_wp_error( $resized_file ) ) { + $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] ); + $img_url = $upload_url . $resized_rel_path; + } else { + throw new WPSP_Exception('Unable to save resized image file: ' . $editor->get_error_message()); + } + + } + } + + // Okay, leave the ship. + if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'WPSP_upscale' ) ); + + // Return the output. + if ( $single ) { + // str return. + $image = $img_url; + } else { + // array return. + $image = array ( + 0 => $img_url, + 1 => $dst_w, + 2 => $dst_h + ); + } + + return $image; + } + catch (WPSP_Exception $ex) { + error_log('WPSP_Resize.process() error: ' . $ex->getMessage()); + + if ($this->throwOnError) { + // Bubble up exception. + throw $ex; + } + else { + // Return false, so that this patch is backwards-compatible. + return false; + } + } + } + + /** + * Callback to overwrite WP computing of thumbnail measures + */ + function WPSP_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) { + if ( ! $crop ) return null; // Let the wordpress default function handle this. + // Here is the point we allow to use larger image size than the original one. + $aspect_ratio = $orig_w / $orig_h; + $new_w = $dest_w; + $new_h = $dest_h; + if ( ! $new_w ) { + $new_w = intval( $new_h * $aspect_ratio ); + } + if ( ! $new_h ) { + $new_h = intval( $new_w / $aspect_ratio ); + } + $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h ); + $crop_w = round( $new_w / $size_ratio ); + $crop_h = round( $new_h / $size_ratio ); + $s_x = floor( ( $orig_w - $crop_w ) / 2 ); + $s_y = floor( ( $orig_h - $crop_h ) / 2 ); + return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h ); + } + } +} + +if ( ! function_exists( 'WPSP_Resize' ) ) : + /** + * This is just a tiny wrapper function for the class above so that there is no + * need to change any code in your own WP themes. Usage is still the same :) + */ + function WPSP_Resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) { + /* WPML Fix */ + if ( defined( 'ICL_SITEPRESS_VERSION' ) ){ + global $sitepress; + $url = $sitepress->convert_url( $url, $sitepress->get_default_language() ); + } + + /* Jetpack Photon fix */ + if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) && function_exists( 'jetpack_photon_url' ) ) { + $type = ( $crop ) ? 'resize' : 'fit'; + $args = array( $type => $width . ',' . $height ); + return jetpack_photon_url( $url, $args ); + } + + $WPSP_Resize = WPSP_Resize::getInstance(); + return $WPSP_Resize->process( $url, $width, $height, $crop, $single, $upscale ); + } +endif; \ No newline at end of file diff --git a/inc/styling.php b/inc/styling.php new file mode 100644 index 0000000..f89bf9e --- /dev/null +++ b/inc/styling.php @@ -0,0 +1,59 @@ + array( + 'margin-left' => ( '' !== $settings[ 'columns_gutter' ] && '12' !== $settings[ 'columns' ] ) ? '-' . $settings[ 'columns_gutter' ] : null + ), + + '.wp-show-posts-columns#wpsp-' . $settings[ 'list_id' ] . ' .wp-show-posts-inner' => array( + 'margin' => ( '' !== $settings[ 'columns_gutter' ] && '12' !== $settings[ 'columns' ] ) ? '0 0 ' . $settings[ 'columns_gutter' ] . ' ' . $settings[ 'columns_gutter' ] : null, + ), + + ); + + // Output the above CSS + $output = ''; + foreach( $visual_css as $k => $properties ) { + + if ( !count( $properties ) ) { + continue; + } + + $temporary_output = $k . ' {'; + $elements_added = 0; + + foreach( $properties as $p => $v ) { + + if ( empty( $v ) ) { + continue; + } + + $elements_added++; + $temporary_output .= $p . ': ' . $v . '; '; + + } + + $temporary_output .= "}"; + + if ( $elements_added > 0 ) { + $output .= $temporary_output; + } + + } + + $output = str_replace(array("\r", "\n"), '', $output); + + if ( '' !== $output ) { + echo ''; + } +} \ No newline at end of file diff --git a/js/jquery.matchHeight.js b/js/jquery.matchHeight.js new file mode 100644 index 0000000..b275b49 --- /dev/null +++ b/js/jquery.matchHeight.js @@ -0,0 +1,399 @@ +/** +* jquery-match-height master by @liabru +* http://brm.io/jquery-match-height/ +* License: MIT +*/ + +;(function(factory) { // eslint-disable-line no-extra-semi + 'use strict'; + if (typeof define === 'function' && define.amd) { + // AMD + define(['jquery'], factory); + } else if (typeof module !== 'undefined' && module.exports) { + // CommonJS + module.exports = factory(require('jquery')); + } else { + // Global + factory(jQuery); + } +})(function($) { + /* + * internal + */ + + var _previousResizeWidth = -1, + _updateTimeout = -1; + + /* + * _parse + * value parse utility function + */ + + var _parse = function(value) { + // parse value and convert NaN to 0 + return parseFloat(value) || 0; + }; + + /* + * _rows + * utility function returns array of jQuery selections representing each row + * (as displayed after float wrapping applied by browser) + */ + + var _rows = function(elements) { + var tolerance = 1, + $elements = $(elements), + lastTop = null, + rows = []; + + // group elements by their top position + $elements.each(function(){ + var $that = $(this), + top = $that.offset().top - _parse($that.css('margin-top')), + lastRow = rows.length > 0 ? rows[rows.length - 1] : null; + + if (lastRow === null) { + // first item on the row, so just push it + rows.push($that); + } else { + // if the row top is the same, add to the row group + if (Math.floor(Math.abs(lastTop - top)) <= tolerance) { + rows[rows.length - 1] = lastRow.add($that); + } else { + // otherwise start a new row group + rows.push($that); + } + } + + // keep track of the last row top + lastTop = top; + }); + + return rows; + }; + + /* + * _parseOptions + * handle plugin options + */ + + var _parseOptions = function(options) { + var opts = { + byRow: true, + property: 'height', + target: null, + remove: false + }; + + if (typeof options === 'object') { + return $.extend(opts, options); + } + + if (typeof options === 'boolean') { + opts.byRow = options; + } else if (options === 'remove') { + opts.remove = true; + } + + return opts; + }; + + /* + * matchHeight + * plugin definition + */ + + var matchHeight = $.fn.matchHeight = function(options) { + var opts = _parseOptions(options); + + // handle remove + if (opts.remove) { + var that = this; + + // remove fixed height from all selected elements + this.css(opts.property, ''); + + // remove selected elements from all groups + $.each(matchHeight._groups, function(key, group) { + group.elements = group.elements.not(that); + }); + + // TODO: cleanup empty groups + + return this; + } + + if (this.length <= 1 && !opts.target) { + return this; + } + + // keep track of this group so we can re-apply later on load and resize events + matchHeight._groups.push({ + elements: this, + options: opts + }); + + // match each element's height to the tallest element in the selection + matchHeight._apply(this, opts); + + return this; + }; + + /* + * plugin global options + */ + + matchHeight.version = 'master'; + matchHeight._groups = []; + matchHeight._throttle = 80; + matchHeight._maintainScroll = false; + matchHeight._beforeUpdate = null; + matchHeight._afterUpdate = null; + matchHeight._rows = _rows; + matchHeight._parse = _parse; + matchHeight._parseOptions = _parseOptions; + + /* + * matchHeight._apply + * apply matchHeight to given elements + */ + + matchHeight._apply = function(elements, options) { + var opts = _parseOptions(options), + $elements = $(elements), + rows = [$elements]; + + // take note of scroll position + var scrollTop = $(window).scrollTop(), + htmlHeight = $('html').outerHeight(true); + + // get hidden parents + var $hiddenParents = $elements.parents().filter(':hidden'); + + // cache the original inline style + $hiddenParents.each(function() { + var $that = $(this); + $that.data('style-cache', $that.attr('style')); + }); + + // temporarily must force hidden parents visible + $hiddenParents.css('display', 'block'); + + // get rows if using byRow, otherwise assume one row + if (opts.byRow && !opts.target) { + + // must first force an arbitrary equal height so floating elements break evenly + $elements.each(function() { + var $that = $(this), + display = $that.css('display'); + + // temporarily force a usable display value + if (display !== 'inline-block' && display !== 'flex' && display !== 'inline-flex') { + display = 'block'; + } + + // cache the original inline style + $that.data('style-cache', $that.attr('style')); + + $that.css({ + 'display': display, + 'padding-top': '0', + 'padding-bottom': '0', + 'margin-top': '0', + 'margin-bottom': '0', + 'border-top-width': '0', + 'border-bottom-width': '0', + 'height': '100px', + 'overflow': 'hidden' + }); + }); + + // get the array of rows (based on element top position) + rows = _rows($elements); + + // revert original inline styles + $elements.each(function() { + var $that = $(this); + $that.attr('style', $that.data('style-cache') || ''); + }); + } + + $.each(rows, function(key, row) { + var $row = $(row), + targetHeight = 0; + + if (!opts.target) { + // skip apply to rows with only one item + if (opts.byRow && $row.length <= 1) { + $row.css(opts.property, ''); + return; + } + + // iterate the row and find the max height + $row.each(function(){ + var $that = $(this), + style = $that.attr('style'), + display = $that.css('display'); + + // temporarily force a usable display value + if (display !== 'inline-block' && display !== 'flex' && display !== 'inline-flex') { + display = 'block'; + } + + // ensure we get the correct actual height (and not a previously set height value) + var css = { 'display': display }; + css[opts.property] = ''; + $that.css(css); + + // find the max height (including padding, but not margin) + if ($that.outerHeight(false) > targetHeight) { + targetHeight = $that.outerHeight(false); + } + + // revert styles + if (style) { + $that.attr('style', style); + } else { + $that.css('display', ''); + } + }); + } else { + // if target set, use the height of the target element + targetHeight = opts.target.outerHeight(false); + } + + // iterate the row and apply the height to all elements + $row.each(function(){ + var $that = $(this), + verticalPadding = 0; + + // don't apply to a target + if (opts.target && $that.is(opts.target)) { + return; + } + + // handle padding and border correctly (required when not using border-box) + if ($that.css('box-sizing') !== 'border-box') { + verticalPadding += _parse($that.css('border-top-width')) + _parse($that.css('border-bottom-width')); + verticalPadding += _parse($that.css('padding-top')) + _parse($that.css('padding-bottom')); + } + + // set the height (accounting for padding and border) + $that.css(opts.property, (targetHeight - verticalPadding) + 'px'); + }); + }); + + // revert hidden parents + $hiddenParents.each(function() { + var $that = $(this); + $that.attr('style', $that.data('style-cache') || null); + }); + + // restore scroll position if enabled + if (matchHeight._maintainScroll) { + $(window).scrollTop((scrollTop / htmlHeight) * $('html').outerHeight(true)); + } + + return this; + }; + + /* + * matchHeight._applyDataApi + * applies matchHeight to all elements with a data-match-height attribute + */ + + matchHeight._applyDataApi = function() { + var groups = {}; + + // generate groups by their groupId set by elements using data-match-height + $('[data-match-height], [data-mh]').each(function() { + var $this = $(this), + groupId = $this.attr('data-mh') || $this.attr('data-match-height'); + + if (groupId in groups) { + groups[groupId] = groups[groupId].add($this); + } else { + groups[groupId] = $this; + } + }); + + // apply matchHeight to each group + $.each(groups, function() { + this.matchHeight(true); + }); + }; + + /* + * matchHeight._update + * updates matchHeight on all current groups with their correct options + */ + + var _update = function(event) { + if (matchHeight._beforeUpdate) { + matchHeight._beforeUpdate(event, matchHeight._groups); + } + + $.each(matchHeight._groups, function() { + matchHeight._apply(this.elements, this.options); + }); + + if (matchHeight._afterUpdate) { + matchHeight._afterUpdate(event, matchHeight._groups); + } + }; + + matchHeight._update = function(throttle, event) { + // prevent update if fired from a resize event + // where the viewport width hasn't actually changed + // fixes an event looping bug in IE8 + if (event && event.type === 'resize') { + var windowWidth = $(window).width(); + if (windowWidth === _previousResizeWidth) { + return; + } + _previousResizeWidth = windowWidth; + } + + // throttle updates + if (!throttle) { + _update(event); + } else if (_updateTimeout === -1) { + _updateTimeout = setTimeout(function() { + _update(event); + _updateTimeout = -1; + }, matchHeight._throttle); + } + }; + + /* + * bind events + */ + + // apply on DOM ready event + $(matchHeight._applyDataApi); + + // update heights on load and resize events + $(window).bind('load', function(event) { + matchHeight._update(false, event); + }); + + // throttled update heights on resize events + $(window).bind('resize orientationchange', function(event) { + matchHeight._update(true, event); + }); + +}); + +jQuery(document).ready( function($) { + var s = document.body || document.documentElement, s = s.style; + if ( s.webkitFlexWrap == '' || s.msFlexWrap == '' || s.flexWrap == '' ) return false; + + jQuery('.wp-show-posts-columns .wp-show-posts-inner').matchHeight(); + + var rows = $.fn.matchHeight._rows($('.wp-show-posts-columns .wp-show-posts-inner')); + + $.each(rows, function(i, row) { + row.first().addClass('generate-column-first'); + row.last().addClass('generate-column-last'); + }); +}); \ No newline at end of file diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..30dcab4 --- /dev/null +++ b/license.txt @@ -0,0 +1,29 @@ +WP Show Posts is licensed under the GNU General Public License v2 or later +More details here: http://www.gnu.org/licenses/gpl-2.0.html + +== Bundled resources == + += Butterbean = + +Licensed under the GNU GPL, version 2 or later. +2015-2016 © Justin Tadlock. + += MatchHeight.js = + +jquery.matchHeight.js is licensed under The MIT License (MIT) +Copyright (c) 2014 Liam Brummitt + += FontAwesome = + +Icons generated with IcoMoon with the following licenses: + +Font License: SIL OFL 1.1 - http://scripts.sil.org/OFL +Code License: MIT License - http://opensource.org/licenses/mit-license.html + +All brand icons are trademarks of their respective owners. + += Display Posts Shortcode = + +Some of the base code of this plugin was borrowed from the awesome Display Posts Shortcode plugin by Bill Erickson. +https://wordpress.org/plugins/display-posts-shortcode/ +http://www.billerickson.net/ \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..9c92344 --- /dev/null +++ b/readme.txt @@ -0,0 +1,334 @@ +=== WP Show Posts === +Contributors: edge22 +Donate link: https://wpshowposts.com +Tags: show posts, display posts shortcode, portfolio, gallery, post columns +Requires at least: 4.5 +Tested up to: 4.9 +Stable tag: 1.1.1 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +Add posts to your website from any post type using a simple shortcode. + +== Description == + +https://vimeo.com/175638957 + +WP Show Posts allows you to display posts anywhere on your website using an easy to use shortcode. + +You can pull posts from any post type like WooCommerce, Easy Digital Downloads etc.. + +This plugin works with any theme. + +Here are the features in the free version: + += Posts = + +* Post type +* Taxonomy +* Terms +* Posts per page +* Pagination + += Columns = + +* Columns +* Columns gutter + += Images = + +* Show images +* Image width +* Image height +* Image alignment +* Image location + += Content = + +* Content type (excerpt or full post) +* List type (ordered, unordered or none) +* Excerpt length +* Include title +* Read more text + += Meta = + +* Include author +* Author location +* Include date +* Date location +* Include terms +* Terms location + += More settings = + +* Author ID +* Exclude current +* Post ID +* Exclude post ID +* Ignore sticky posts +* Offset +* Order +* Order by +* Status +* Meta key +* Meta value +* Tax operator +* No results message + += Our *Pro* version has these features = + +https://vimeo.com/175660953 + +[Check out Pro](https://wpshowposts.com/ "Check out Pro") + += Posts = + +* AJAX pagination + += Columns = + +* Masonry +* Featured post +* Background color +* Background color hover +* Border color +* Border color hover + += Images = + +* Image overlay color +* Image overlay icon +* Image hover effect +* Image lightbox +* Image lightbox gallery + += Content = + +* Read more style +* Read more color +* Content link color +* Content link color hover +* Content text color +* Title color +* Title color hover + += Meta = + +* Meta color +* Meta color hover + += Social = + +* Twitter +* Twitter color + hover +* Facebook +* Facebook color + hover +* Google+ +* Google+ color + hover +* Pinterest +* Pinterest color + hover +* Love it +* Alignment + +Check out GeneratePress, our awesome WordPress theme! (http://wordpress.org/themes/generatepress) + +== Installation == + +There's two ways to install WP Show Posts. + +1. Go to "Plugins > Add New" in your Dashboard and search for: WP Show Posts +2. Download the .zip from WordPress.org, and upload the folder to the `/wp-content/plugins/` directory via FTP. + +In most cases, #1 will work fine and is way easier. + +== Frequently Asked Questions == + += How do I create a post list? = + +* Make sure WP Show Posts is activated. +* Navigate to "WP Show Posts > Add New" and configure your list. +* Copy the shortcode provided for you when adding your new list. +* Add your shortcode to your desired page or post. + +== Screenshots == + +1. All of your created post lists. +2. The "Posts" settings tab. +3. The "Columns" settings tab. +4. The "Images" settings tab. +5. The "Content" settings tab. +6. The "Meta" settings tab. +7. The "More query ars" settings tab. + +== Changelog == + += 1.1.1 = +* Fix: Fix image hover effects in WPSP Pro + += 1.1 = +* New: Allow multiple taxonomy terms to be selected +* New: Choose the title HTML element +* New: wpsp_disable_title_link filter +* New: wpsp_disable_image_link filter +* New: wpsp_read_more_output filter +* New: wpsp_inside_wrapper hook +* New: wpsp_image_attributes filter +* New: wpsp_term_separator filter +* New: Option to add comments number/link in post meta +* New: Allow override of settings within shortcode parameter +* New: Add standard post classes to each post +* Tweak: Remove many function_exists() wrappers - check your custom functions! +* Tweak: Pass list settings through hooks instead of using global +* Tweak: Clean up code considerably +* Tweak: Use the_excerpt() instead of custom function +* Tweak: Remove border radius from read more buttons +* Fix: Broken author setting +* Fix: Remove image float on mobile +* Fix: Missing color labels in WP 4.9 + += 1.0 = +* Add new hook inside image container: wpsp_inside_image_container +* Fix issue with pagination and random post ordering +* Clean up defaults to only include free options +* Add margin to the top of pagination +* Use manual excerpt if it's set + += 0.9 = +* Fix bug where terms weren't saving +* Strip oembed URLs from excerpt + += 0.8 = +* Strip shortcodes from excerpts +* Add ellipses after excerpts +* Fix some broken text domains for translations + += 0.7 = +* Prevent direct access to files +* Add prefix to all column classes to avoid conflicts +* Use wp_trim_words() function for excerpts +* Fix conflict with Maintenance plugin +* Make columns full width on mobile +* Allow more tag usage when excerpt is set +* Add blank option in widget to fix bug in Customizer/Elementor + += 0.6 = +* Add height: auto to images to prevent image stretching in Beaver Builder +* Prevent horizontal scrolling when posts are in columns +* Change "More query args" section name to "More settings" +* Allow multiple IDs in "Post ID" option +* Add "Exclude IDs" option +* Add "No results message" option +* Add "WP Show Posts" widget to add posts in widget areas + += 0.5 = +* Fix conflict with Yoast SEO causing taxonomy and terms fields to be blank +* Add support for translations + += 0.4 = +* Fix column width issue when content is disabled +* Fix pagination issue when post list is on the front page +* Disable pagination in single posts +* Fix saving of taxonomy and terms fields +* Force no underline on read more buttons + += 0.3 = +* Remove attachment post type from list for now +* Don't show pagination if there's no posts +* Move wpsp_before_title hook into the
    element +* New hook: wpsp_before_wrapper +* New hook: wpsp_before_header + += 0.2 = +* Fix issue with posts showing up in wrong area on page +* Remove read more link if the tag is used +* Wrap read more button in div: .wpsp-read-more + += 0.1 = +* Initial release + +== Upgrade Notice == + += 1.1.1 = +* Fix: Fix image hover effects in WPSP Pro + += 1.1 = +* New: Allow multiple taxonomy terms to be selected +* New: Choose the title HTML element +* New: wpsp_disable_title_link filter +* New: wpsp_disable_image_link filter +* New: wpsp_read_more_output filter +* New: wpsp_inside_wrapper hook +* New: wpsp_image_attributes filter +* New: wpsp_term_separator filter +* New: Option to add comments number/link in post meta +* New: Allow override of settings within shortcode parameter +* New: Add standard post classes to each post +* Tweak: Remove many function_exists() wrappers - check your custom functions! +* Tweak: Pass list settings through hooks instead of using global +* Tweak: Clean up code considerably +* Tweak: Use the_excerpt() instead of custom function +* Tweak: Remove border radius from read more buttons +* Fix: Broken author setting +* Fix: Remove image float on mobile +* Fix: Missing color labels in WP 4.9 + += 1.0 = +* Add new hook inside image container: wpsp_inside_image_container +* Fix issue with pagination and random post ordering +* Clean up defaults to only include free options +* Add margin to the top of pagination +* Use manual excerpt if it's set + += 0.9 = +* Fix bug where terms weren't saving +* Strip oembed URLs from excerpt + += 0.8 = +* Strip shortcodes from excerpts +* Add ellipses after excerpts +* Fix some broken text domains for translations + += 0.7 = +* Prevent direct access to files +* Add prefix to all column classes to avoid conflicts +* Use wp_trim_words() function for excerpts +* Fix conflict with Maintenance plugin +* Make columns full width on mobile +* Allow more tag usage when excerpt is set +* Add blank option in widget to fix bug in Customizer/Elementor + += 0.6 = +* Add height: auto to images to prevent image stretching in Beaver Builder +* Prevent horizontal scrolling when posts are in columns +* Change "More query args" section name to "More settings" +* Allow multiple IDs in "Post ID" option +* Add "Exclude IDs" option +* Add "No results message" option +* Add "WP Show Posts" widget to add posts in widget areas + += 0.5 = +* Fix conflict with Yoast SEO causing taxonomy and terms fields to be blank +* Add support for translations + += 0.4 = +* Fix column width issue when content is disabled +* Fix pagination issue when post list is on the front page +* Disable pagination in single posts +* Fix saving of taxonomy and terms fields +* Force no underline on read more buttons + += 0.3 = +* Remove attachment post type from list for now +* Don't show pagination if there's no posts +* Move wpsp_before_title hook into the
    element +* New hook: wpsp_before_wrapper +* New hook: wpsp_before_header + += 0.2 = +* Fix issue with posts showing up in wrong area on page +* Remove read more link if the tag is used +* Wrap read more button in div: .wpsp-read-more + += 0.1 = +* Initial release diff --git a/wp-show-posts.php b/wp-show-posts.php new file mode 100644 index 0000000..1265ebc --- /dev/null +++ b/wp-show-posts.php @@ -0,0 +1,571 @@ + absint( $id ), + 'author' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_author' ) ), + 'columns' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_columns' ) ), + 'columns_gutter' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_columns_gutter' ) ), + 'content_type' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_content_type' ) ), + 'list_type' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_list_type' ) ), + 'exclude_current' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_exclude_current' ) ), + 'excerpt_length' => absint( wpsp_get_setting( $id, 'wpsp_excerpt_length' ) ), + 'post_id' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_id' ) ), + 'exclude_post_id' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_exclude_post_id' ) ), + 'ignore_sticky_posts' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_ignore_sticky_posts' ) ), + 'include_title' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_title', true ) ), + 'title_element' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_title_element' ) ), + 'image' => sanitize_text_field( get_post_meta( $id, 'wpsp_image', true ), FILTER_VALIDATE_BOOLEAN ), + 'image_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_image_location' ) ), + 'image_alignment' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_image_alignment' ) ), + 'image_height' => absint( wpsp_get_setting( $id, 'wpsp_image_height' ) ), + 'image_width' => absint( wpsp_get_setting( $id, 'wpsp_image_width' ) ), + 'include_author' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_include_author' ) ), + 'author_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_author_location' ) ), + 'include_terms' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_include_terms' ) ), + 'terms_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_terms_location' ) ), + 'include_date' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_date', true ) ), + 'date_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_date_location' ) ), + 'include_comments' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_comments', true ) ), + 'comments_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_comments_location' ) ), + 'inner_wrapper' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_inner_wrapper' ) ), + 'inner_wrapper_class' => array_map( 'sanitize_html_class', ( explode( ' ', wpsp_get_setting( $id, 'wpsp_inner_wrapper_class' ) ) ) ), + 'inner_wrapper_style' => explode( ' ', esc_attr( wpsp_get_setting( $id, 'wpsp_inner_wrapper_style' ) ) ), + 'itemtype' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_itemtype' ) ), + 'meta_key' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_meta_key' ) ), + 'meta_value' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_meta_value' ) ), + 'offset' => absint( wpsp_get_setting( $id, 'wpsp_offset' ) ), + 'order' => sanitize_key( wpsp_get_setting( $id, 'wpsp_order' ) ), + 'orderby' => sanitize_key( wpsp_get_setting( $id, 'wpsp_orderby' ) ), + 'pagination' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_pagination' ) ), + 'post_type' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_type' ) ), + 'post_status' => wpsp_get_setting( $id, 'wpsp_post_status' ), // Validated later + 'posts_per_page' => intval( wpsp_get_setting( $id, 'wpsp_posts_per_page' ) ), + 'tax_operator' => wpsp_get_setting( $id, 'wpsp_tax_operator' ), // Validated later + 'tax_term' => wpsp_get_setting( $id, 'wpsp_tax_term' ), + 'taxonomy' => sanitize_key( wpsp_get_setting( $id, 'wpsp_taxonomy' ) ), + 'read_more_text' => wp_kses_post( wpsp_get_setting( $id, 'wpsp_read_more_text' ) ), + 'wrapper' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_wrapper' ) ), + 'wrapper_class' => array_map( 'sanitize_html_class', ( explode( ' ', wpsp_get_setting( $id, 'wpsp_wrapper_class' ) ) ) ), + 'wrapper_style' => explode( ' ', esc_attr( wpsp_get_setting( $id, 'wpsp_wrapper_style' ) ) ), + 'no_results' => wp_kses_post( wpsp_get_setting( $id, 'wpsp_no_results' ) ), + 'post_meta_bottom_style' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_meta_bottom_style' ) ), + 'post_meta_top_style' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_meta_top_style' ) ), + ) ); + + // Replace args with any custom args. + if ( ! empty( $custom_settings ) ) { + if ( is_array( $custom_settings ) ) { + $settings = array_merge( $settings, $custom_settings ); + } + + if ( ! is_array( $custom_settings ) ) { + $settings_string = parse_str( $custom_settings, $custom_settings ); + $settings = array_merge( $settings, $custom_settings ); + } + } + + // Grab initiate args for query + $args = array(); + + if ( '' !== $settings[ 'order' ] ) { + $args[ 'order' ] = $settings[ 'order' ]; + } + + if ( '' !== $settings[ 'orderby' ] ) { + $args[ 'orderby' ] = $settings[ 'orderby' ]; + } + + if ( 'rand' == $settings[ 'orderby' ] && $settings[ 'pagination' ] ) { + $args[ 'orderby' ] = 'rand(' . $id . ')'; + } + + if ( '' !== $settings[ 'post_type' ] ) { + $args[ 'post_type' ] = $settings[ 'post_type' ]; + } + + if ( '' !== $settings[ 'posts_per_page' ] ) { + $args[ 'posts_per_page' ] = $settings[ 'posts_per_page' ]; + } + + if ( $settings[ 'ignore_sticky_posts' ] ) { + $args[ 'ignore_sticky_posts' ] = $settings[ 'ignore_sticky_posts' ]; + } + + if ( '' !== $settings[ 'meta_key' ] ) { + $args[ 'meta_key' ] = $settings[ 'meta_key' ]; + } + + if ( '' !== $settings[ 'meta_value' ] ) { + $args[ 'meta_value' ] = $settings[ 'meta_value' ]; + } + + if ( $settings[ 'offset' ] > 0 ) { + $args[ 'offset' ] = $settings[ 'offset' ]; + } + + if ( '' !== $settings[ 'author' ] ) { + $args[ 'author' ] = $settings[ 'author' ]; + } + + if ( $settings[ 'pagination' ] && ! is_single() ) { + $paged_query = is_front_page() ? 'page' : 'paged'; + $args[ 'paged' ] = get_query_var( $paged_query ); + } + + // Post Status + $settings[ 'post_status' ] = explode( ', ', $settings[ 'post_status' ] ); + $validated = array(); + $available = array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash', 'any' ); + + foreach ( $settings[ 'post_status' ] as $unvalidated ) { + if ( in_array( $unvalidated, $available ) ) { + $validated[] = $unvalidated; + } + } + + if ( ! empty( $validated ) ) { + $args['post_status'] = $validated; + } + + // If taxonomy attributes, create a taxonomy query + if ( ! empty( $settings[ 'taxonomy' ] ) && ! empty( $settings[ 'tax_term' ] ) ) { + + if ( is_array( $settings[ 'tax_term' ] ) ) { + $settings[ 'tax_term' ] = implode( ', ', $settings[ 'tax_term' ] ); + } + + if ( 'current' == $settings[ 'tax_term' ] ) { + global $post; + $terms = wp_get_post_terms(get_the_ID(), $settings[ 'taxonomy' ]); + $settings[ 'tax_term' ] = array(); + foreach ($terms as $term) { + $settings[ 'tax_term' ][] = $term->slug; + } + } else { + // Term string to array + $settings[ 'tax_term' ] = explode( ', ', $settings[ 'tax_term' ] ); + } + + // Validate operator + if ( ! in_array( $settings[ 'tax_operator' ], array( 'IN', 'NOT IN', 'AND' ) ) ) { + $settings[ 'tax_operator' ] = 'IN'; + } + + $tax_args = array( + 'tax_query' => array( + array( + 'taxonomy' => $settings[ 'taxonomy' ], + 'field' => 'slug', + 'terms' => $settings[ 'tax_term' ], + 'operator' => $settings[ 'tax_operator' ] + ) + ) + ); + + $args = array_merge( $args, $tax_args ); + + } + + // If Post IDs + if ( $settings[ 'post_id' ] ) { + $posts_in = array_map( 'intval', explode( ',', $settings[ 'post_id' ] ) ); + $args['post__in'] = $posts_in; + } + + // If Exclude Post IDs + if ( $settings[ 'exclude_post_id' ] ) { + $posts_not_in = array_map( 'intval', explode( ',', $settings[ 'exclude_post_id' ] ) ); + $args['post__not_in'] = $posts_not_in; + } + + // If Exclude Current + if ( ( is_singular() && $settings[ 'exclude_current' ] ) || is_single() ) { + $args['post__not_in'] = array( get_the_ID() ); + } + + // Border + if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) { + $border = wpsp_sanitize_hex_color( wpsp_get_setting( $settings['list_id'], 'wpsp_border' ) ); + if ( '' !== $border ) { + $settings['wrapper_class'][] = 'include-border'; + if ( ! function_exists( 'wpsp_styling' ) ) { + $border = 'border-color: ' . $border . ';'; + } + } + } + + // Padding + if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) { + $padding = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_padding' ) ); + if ( '' !== $padding ) { + $settings['wrapper_class'][] = 'include-padding'; + $padding = 'padding:' . $padding . ';'; + } + } + + // Columns + if ( 'col-12' !== $settings[ 'columns' ] ) { + wp_enqueue_script( 'wpsp-matchHeight', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/jquery.matchHeight.js', array( 'jquery' ), WPSP_VERSION, true ); + $settings[ 'wrapper_class' ][] = 'wp-show-posts-columns'; + } + + // Featured post class + $featured_post = wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_featured_post' ) ); + + $current_post = ''; + if ( 'col-12' !== $settings[ 'columns' ] && $featured_post ) { + if ( $settings[ 'columns' ] == 'col-6' ) { + $current_post = 'wpsp-col-12'; + } + + if ( $settings[ 'columns' ] == 'col-4' ) { + $current_post = 'wpsp-col-8'; + } + + if ( $settings[ 'columns' ] == 'col-3' ) { + $current_post = 'wpsp-col-6'; + } + + if ( $settings[ 'columns' ] == 'col-20' ) { + $current_post = 'wpsp-col-6'; + } + } + + // Masonry + $masonry = wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_masonry' ) ); + + if ( $masonry ) { + $settings[ 'wrapper_class' ][] = 'wp-show-posts-masonry'; + $settings[ 'inner_wrapper_class' ][] = ' wp-show-posts-masonry-' . $settings[ 'columns' ]; + $settings[ 'inner_wrapper_class' ][] = ' wp-show-posts-masonry-block'; + + wp_enqueue_script( 'wpsp-imagesloaded' ); + wp_enqueue_script( 'jquery-masonry' ); + wp_add_inline_script( 'jquery-masonry', 'jQuery(function($){var $container = $(".wp-show-posts-masonry");$container.imagesLoaded( function(){$container.fadeIn( 1000 ).masonry({itemSelector : ".wp-show-posts-masonry-block",columnWidth: ".grid-sizer"}).css("opacity","1");});});' ); + } + + // Add the default inner wrapper class + // We don't create the class element up here like below, as we need to add classes inside the loop below as well + $settings[ 'inner_wrapper_class' ][] = 'wp-show-posts-single'; + + if ( 'col-12' == $settings[ 'columns' ] ) { + $settings[ 'inner_wrapper_class' ][] = 'wpsp-clearfix'; + } + + // Add the default wrapper class + $settings[ 'wrapper_class' ][] = 'wp-show-posts'; + + // Get the wrapper class + if ( ! empty( $settings[ 'wrapper_class' ] ) ) { + $settings[ 'wrapper_class' ] = ' class="' . implode( ' ', $settings[ 'wrapper_class' ] ) . '"'; + } + + // Get the wrapper style + if ( ! empty( $settings[ 'wrapper_style' ] ) ) { + $settings[ 'wrapper_style' ] = ' style="' . implode( ' ', $settings[ 'wrapper_style' ] ) . '"'; + } + + // Get the inner wrapper class + if ( ! empty( $settings[ 'inner_wrapper_style' ] ) ) { + $settings[ 'inner_wrapper_style' ] = ' style="' . implode( ' ', $settings[ 'inner_wrapper_style' ] ) . '"'; + } + + // Get the wrapper ID + $wrapper_id = ' id="wpsp-' . $id . '"'; + + $wrapper_atts = apply_filters( 'wpsp_wrapper_atts', '' ); + + do_action( 'wpsp_before_wrapper', $settings ); + + // Start the wrapper + echo '<' . $settings[ 'wrapper' ] . $wrapper_id . $settings[ 'wrapper_class' ] . $settings[ 'wrapper_style' ] . $wrapper_atts . '>'; + + do_action( 'wpsp_inside_wrapper', $settings ); + + if ( $masonry ) { + echo '
    '; + } + + // Start the query + $query = new WP_Query( apply_filters( 'wp_show_posts_shortcode_args', $args ) ); + + if ( $settings['list_type'] == 'ordered' ): + echo "
      "; + elseif ( $settings['list_type'] == 'unordered' ): + echo "
        "; + endif; + + // Start the loop + if ( $query->have_posts() ) { + while ( $query->have_posts() ) { + echo $settings['list_type'] != 'none' ? "
      • " : ""; + + $query->the_post(); + + // Get page + $paged_query = is_front_page() ? 'page' : 'paged'; + $paged = ( get_query_var( $paged_query ) ) ? get_query_var( $paged_query ) : 1; + + $featured = ''; + $column_class = ''; + + // Featured post + if ( $settings[ 'columns' ] !== 'col-12' && $featured_post ) { + if ( $query->current_post == 0 && $paged == 1 ) { + $featured = ' featured-column ' . $current_post; + } else { + $featured = ' wpsp-' . $settings[ 'columns' ]; + } + } elseif ( $settings[ 'columns' ] !== 'col-12' ) { + $column_class .= ' wpsp-' . $settings[ 'columns' ]; + } + + // Merge our classes with the post classes. + $settings['inner_wrapper_class'] = array_merge( $settings['inner_wrapper_class'], get_post_class() ); + + // Start inner container + printf( '<%1$s class="%2$s" itemtype="http://schema.org/%3$s" itemscope>', + $settings[ 'inner_wrapper' ], + implode( ' ', $settings[ 'inner_wrapper_class' ] ) . $column_class . $featured, + $settings[ 'itemtype' ] + ); + echo '
        '; + + do_action( 'wpsp_before_header', $settings ); + + // The title + if ( $settings[ 'include_title' ] || ( $settings[ 'include_author' ] && 'below-title' == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && 'below-title' == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && 'below-title' == $settings[ 'terms_location' ] ) ) : ?> +
        + ', + $settings[ 'title_element' ], + esc_url( get_permalink() ) + ); + + $after_title = ''; + + if ( apply_filters( 'wpsp_disable_title_link', false, $settings ) ) { + $before_title = '<' . $settings[ 'title_element' ] . ' class="wp-show-posts-entry-title" itemprop="headline">'; + $after_title = ''; + } + + if ( $settings[ 'include_title' ] ) { + the_title( $before_title, $after_title ); + } + + do_action( 'wpsp_after_title', $settings ); + ?> +
        + post_content, '' ) ); + + // The excerpt or full content + if ( 'excerpt' == $settings[ 'content_type' ] && $settings[ 'excerpt_length' ] && ! $more_tag && 'none' !== $settings[ 'content_type' ] ) : ?> +
        + +
        + +
        + +
        + '; + + if ( 'col-12' == $settings[ 'columns' ] ) { + echo '
        '; + } + + // End inner container + echo ''; + echo $settings['list_type'] != 'none' ? "
      • " : ""; + } + } else { + // no posts found + echo $settings[ 'columns' ] !== 'col-12' ? '
        ' : ''; + echo wpautop( $settings[ 'no_results' ] ); + echo $settings[ 'columns' ] !== 'col-12' ? '
        ' : ''; + } + + if ( $settings['list_type'] == 'ordered' ): + echo "
    "; + elseif ( $settings['list_type'] == 'unordered' ): + echo ""; + endif; + + if ( $settings[ 'columns' ] !== 'col-12' ) { + echo '
    '; + } + + echo ''; + + do_action( 'wpsp_after_wrapper', $settings ); + + // Pagination + if ( $settings[ 'pagination' ] && $query->have_posts() && ! is_single() ) { + $ajax_pagination = wp_validate_boolean( wpsp_get_setting( $settings['list_id'], 'wpsp_ajax_pagination' ) ); + + if ( $ajax_pagination && function_exists( 'wpsp_ajax_pagination' ) ) { + + $max_page = $query->max_num_pages; + $nextpage = intval( $paged ) + 1; + + if ( $nextpage <= $max_page ) { + $next_page_url = next_posts( $max_page, false ); + } + + wpsp_ajax_pagination( $next_page_url, $paged, $max_page ); + wp_enqueue_script( 'wpsp-imagesloaded' ); + wp_enqueue_script( 'wpsp-ajax-pagination' ); + } else { + wpsp_pagination( $query->max_num_pages ); + } + } + + if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) { + // Lightbox and gallery + $image_lightbox = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_image_lightbox' ) ); + if ( $image_lightbox ) { + wp_enqueue_script( 'wpsp-featherlight' ); + wp_enqueue_style( 'wpsp-featherlight' ); + + $image_gallery = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_image_gallery' ) ); + if ( $image_gallery ) { + wp_enqueue_script( 'wpsp-featherlight-gallery' ); + wp_enqueue_style( 'wpsp-featherlight-gallery' ); + } + } + } + + // Restore original Post Data + wp_reset_postdata(); +} + +add_shortcode( 'wp_show_posts', 'wpsp_shortcode_function' ); +/* + * Build the shortcode + * + * @since 0.1 + * + * @param array $atts The shortcode attributes. + */ +function wpsp_shortcode_function( $atts ) { + $atts = shortcode_atts( + array( + 'id' => '', + 'settings' => '' + ), $atts, 'wp_show_posts' + ); + + ob_start(); + + if ( $atts[ 'id' ] ) { + wpsp_display( $atts[ 'id' ], $atts[ 'settings' ] ); + } + + return ob_get_clean(); +} From 1160f6d35d30103ee2f07eeb645cd9a4d272623e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Humbert?= Date: Tue, 23 Jan 2018 14:58:23 +0100 Subject: [PATCH 02/18] Add ability to display posts as a list --- admin/metabox.php | 26 +++++++++++++++++ css/wp-show-posts-min.css | 1 - inc/compat.php | 46 ------------------------------ inc/defaults.php | 4 +++ inc/deprecated.php | 10 ------- inc/styling.php | 59 --------------------------------------- readme.txt | 4 +++ wp-show-posts.php | 35 +++++++++++++++++++++++ 8 files changed, 69 insertions(+), 116 deletions(-) delete mode 100644 css/wp-show-posts-min.css delete mode 100644 inc/compat.php delete mode 100644 inc/deprecated.php delete mode 100644 inc/styling.php diff --git a/admin/metabox.php b/admin/metabox.php index bf30565..b5dbefd 100644 --- a/admin/metabox.php +++ b/admin/metabox.php @@ -390,6 +390,32 @@ function wpsp_register( $butterbean, $post_type ) { ); $manager->register_control( +<<<<<<< HEAD +======= + 'wpsp_list_type', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_content', + 'label' => esc_html__( 'List type', 'wp-show-posts' ), + 'choices' => array( + 'ordered' => __( 'Ordered','wp-show-posts' ), + 'unordered' => __( 'Unordered','wp-show-posts' ), + 'none' => __( 'None','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-list-type' ) + ) + ); + + $manager->register_setting( + 'wpsp_list_type', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_list_type' ] ? $defaults[ 'wpsp_list_type' ] : '' + ) + ); + + $manager->register_control( +>>>>>>> Add ability to display posts as a list 'wpsp_excerpt_length', // Same as setting name. array( 'type' => 'number', diff --git a/css/wp-show-posts-min.css b/css/wp-show-posts-min.css deleted file mode 100644 index 116308d..0000000 --- a/css/wp-show-posts-min.css +++ /dev/null @@ -1 +0,0 @@ -body .wp-show-posts a{box-shadow:0 0 0 transparent}.wp-show-posts-entry-title a{text-decoration:none}a.wp-show-posts-read-more,a.wp-show-posts-read-more:visited{display:inline-block;padding:8px 15px;border:2px solid #222;color:#222;font-size:0.8em;text-decoration:none}.wpsp-read-more{margin:0 0 1em;display:inline-block}a.wp-show-posts-read-more:hover,a.wp-show-posts-read-more:focus{border:2px solid transparent;color:#fff;background:#222;text-decoration:none}.wp-show-posts-image{margin-bottom:1em}.wp-show-posts-image.wpsp-image-left{float:left;margin-right:1.5em}.wp-show-posts-image.wpsp-image-right{float:right;margin-left:1.5em}.wp-show-posts-image.wpsp-image-center{display:block;text-align:center}.wp-show-posts-image img{margin:0 !important;vertical-align:bottom;height:auto}.wp-show-posts-entry-header{margin:0 0 1em;padding:0}.wp-show-posts .wp-show-posts-entry-title{font-size:30px;line-height:1.5em;margin:0}.wp-show-posts-updated{display:none}.wp-show-posts-entry-summary,.wp-show-posts-entry-content{margin-bottom:1em}.wp-show-posts-entry-meta{font-size:0.8em}.wp-show-posts-separator{opacity:0.5}.wp-show-posts-meta a,.wp-show-posts-meta a:visited{color:rgba( 0,0,0,0.5 )}.stack-wp-show-posts-byline,.stack-wp-show-posts-posted-on{display:block}.wp-show-posts-entry-meta-below-post{margin-bottom:1em}.wp-show-posts-columns:not(.wp-show-posts-masonry){display:flex;flex-wrap:wrap}.wp-show-posts-columns .wp-show-posts-single:not(.wp-show-posts-masonry-block){display:flex;flex-direction:row}.wp-show-posts-columns .wp-show-posts-single:not(.wp-show-posts-masonry-block) .wp-show-posts-image img{flex:0 0 auto;object-fit:scale-down}.wpsp-clear{clear:both;display:block;overflow:hidden;visibility:hidden;width:0;height:0}.wp-show-posts:not(.wp-show-posts-columns) .wp-show-posts-single:not(:last-child){margin-bottom:2em}.wpsp-load-more{margin-top:2em}.wp-show-posts-columns .wp-show-posts-entry-title{font-size:25px}.wp-show-posts-columns .wp-show-posts-single.col-md-4 .wp-show-posts-entry-title,.wp-show-posts-columns .wp-show-posts-single.col-md-3 .wp-show-posts-entry-title,.wp-show-posts-columns .wp-show-posts-single.col-md-20 .wp-show-posts-entry-title{font-size:20px}.wp-show-posts-columns .wp-show-posts-inner{flex:1}.wp-show-posts-inner:after{clear:both;display:table;content:'';width:0;height:0;overflow:hidden;visibility:hidden}.wp-show-posts-single.post {margin-bottom: 0;}@media (min-width: 768px){.wpsp-col-1,.wpsp-col-2,.wpsp-col-3,.wpsp-col-4,.wpsp-col-5,.wpsp-col-6,.wpsp-col-7,.wpsp-col-8,.wpsp-col-9,.wpsp-col-10,.wpsp-col-11,.wpsp-col-12,.wpsp-col-20{float:left}.wpsp-col-1{width:8.333333%}.wpsp-col-2{width:16.666667%}.wpsp-col-3{width:25%}.wpsp-col-4{width:33.333%}.wpsp-col-5{width:41.666667%}.wpsp-col-6{width:50%}.wpsp-col-7{width:58.333333%}.wpsp-col-8{width:66.666667%}.wpsp-col-9{width:75%}.wpsp-col-10{width:83.333333%}.wpsp-col-11{width:91.666667%}.wpsp-col-12{width:100%}.wpsp-col-20{width:20%}}@media (max-width: 767px){.wp-show-posts-columns,.wp-show-posts-inner{margin-left:0 !important;margin-right:0 !important}.wp-show-posts-columns .wp-show-posts-single{display:block;width:100%}.wp-show-posts-image.wpsp-image-left,.wp-show-posts-image.wpsp-image-right{float:none;margin-right:0;margin-left:0}}.wp-show-posts-inner *:last-child{margin-bottom:0}.screen-reader-text{clip:rect(1px, 1px, 1px, 1px);position:absolute !important}.screen-reader-text:hover,.screen-reader-text:active,.screen-reader-text:focus{background-color:#f1f1f1;border-radius:3px;box-shadow:0 0 2px 2px rgba(0, 0, 0, 0.6);clip:auto !important;color:#21759b;display:block;font-size:14px;font-weight:bold;height:auto;left:5px;line-height:normal;padding:15px 23px 14px;text-decoration:none;top:5px;width:auto;z-index:100000}.wpsp-clearfix:after{content:".";display:block;overflow:hidden;visibility:hidden;font-size:0;line-height:0;width:0;height:0} diff --git a/inc/compat.php b/inc/compat.php deleted file mode 100644 index 699ba52..0000000 --- a/inc/compat.php +++ /dev/null @@ -1,46 +0,0 @@ - 'col-6', 'wpsp_columns_gutter' => '2em', 'wpsp_content_type' => 'excerpt', +<<<<<<< HEAD +======= + 'wpsp_list_type' => 'none', +>>>>>>> Add ability to display posts as a list 'wpsp_date_location' => 'below-title', 'wpsp_exclude_current' => false, 'wpsp_excerpt_length' => 30, diff --git a/inc/deprecated.php b/inc/deprecated.php deleted file mode 100644 index bbfce86..0000000 --- a/inc/deprecated.php +++ /dev/null @@ -1,10 +0,0 @@ - array( - 'margin-left' => ( '' !== $settings[ 'columns_gutter' ] && '12' !== $settings[ 'columns' ] ) ? '-' . $settings[ 'columns_gutter' ] : null - ), - - '.wp-show-posts-columns#wpsp-' . $settings[ 'list_id' ] . ' .wp-show-posts-inner' => array( - 'margin' => ( '' !== $settings[ 'columns_gutter' ] && '12' !== $settings[ 'columns' ] ) ? '0 0 ' . $settings[ 'columns_gutter' ] . ' ' . $settings[ 'columns_gutter' ] : null, - ), - - ); - - // Output the above CSS - $output = ''; - foreach( $visual_css as $k => $properties ) { - - if ( !count( $properties ) ) { - continue; - } - - $temporary_output = $k . ' {'; - $elements_added = 0; - - foreach( $properties as $p => $v ) { - - if ( empty( $v ) ) { - continue; - } - - $elements_added++; - $temporary_output .= $p . ': ' . $v . '; '; - - } - - $temporary_output .= "}"; - - if ( $elements_added > 0 ) { - $output .= $temporary_output; - } - - } - - $output = str_replace(array("\r", "\n"), '', $output); - - if ( '' !== $output ) { - echo ''; - } -} \ No newline at end of file diff --git a/readme.txt b/readme.txt index bbb0c06..43bd81b 100644 --- a/readme.txt +++ b/readme.txt @@ -46,6 +46,10 @@ Here are the features in the free version: = Content = * Content type (excerpt or full post) +<<<<<<< HEAD +======= +* List type (ordered, unordered or none) +>>>>>>> Add ability to display posts as a list * Excerpt length * Include title * Read more text diff --git a/wp-show-posts.php b/wp-show-posts.php index 69701f2..c561c08 100644 --- a/wp-show-posts.php +++ b/wp-show-posts.php @@ -99,6 +99,10 @@ function wpsp_display( $id, $custom_settings = false ) { 'columns' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_columns' ) ), 'columns_gutter' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_columns_gutter' ) ), 'content_type' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_content_type' ) ), +<<<<<<< HEAD +======= + 'list_type' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_list_type' ) ), +>>>>>>> Add ability to display posts as a list 'exclude_current' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_exclude_current' ) ), 'excerpt_length' => absint( wpsp_get_setting( $id, 'wpsp_excerpt_length' ) ), 'post_id' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_id' ) ), @@ -380,9 +384,24 @@ function wpsp_display( $id, $custom_settings = false ) { // Start the query $query = new WP_Query( apply_filters( 'wp_show_posts_shortcode_args', $args ) ); +<<<<<<< HEAD // Start the loop if ( $query->have_posts() ) { while ( $query->have_posts() ) { +======= + + if ( $settings['list_type'] == 'ordered' ): + echo "
      "; + elseif ( $settings['list_type'] == 'unordered' ): + echo "
        "; + endif; + + // Start the loop + if ( $query->have_posts() ) { + while ( $query->have_posts() ) { + echo $settings['list_type'] != 'none' ? "
      • " : ""; + +>>>>>>> Add ability to display posts as a list $query->the_post(); // Get page @@ -412,7 +431,10 @@ function wpsp_display( $id, $custom_settings = false ) { implode( ' ', $settings[ 'inner_wrapper_class' ] ) . $column_class . $featured, $settings[ 'itemtype' ] ); +<<<<<<< HEAD +======= +>>>>>>> Add ability to display posts as a list echo '
        '; do_action( 'wpsp_before_header', $settings ); @@ -473,6 +495,10 @@ function wpsp_display( $id, $custom_settings = false ) { // End inner container echo ''; +<<<<<<< HEAD +======= + echo $settings['list_type'] != 'none' ? "
      • " : ""; +>>>>>>> Add ability to display posts as a list } } else { // no posts found @@ -481,6 +507,15 @@ function wpsp_display( $id, $custom_settings = false ) { echo $settings[ 'columns' ] !== 'col-12' ? '' : ''; } +<<<<<<< HEAD +======= + if ( $settings['list_type'] == 'ordered' ): + echo "
    "; + elseif ( $settings['list_type'] == 'unordered' ): + echo ""; + endif; + +>>>>>>> Add ability to display posts as a list if ( $settings[ 'columns' ] !== 'col-12' ) { echo '
    '; } From 85989bfa9ca1a6c5502485943a5ca69af99a941d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Humbert?= Date: Tue, 23 Jan 2018 15:55:41 +0100 Subject: [PATCH 03/18] Remove git merge shit --- admin/metabox.php | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/admin/metabox.php b/admin/metabox.php index b5dbefd..ffc082e 100644 --- a/admin/metabox.php +++ b/admin/metabox.php @@ -390,33 +390,7 @@ function wpsp_register( $butterbean, $post_type ) { ); $manager->register_control( -<<<<<<< HEAD -======= - 'wpsp_list_type', // Same as setting name. - array( - 'type' => 'select', - 'section' => 'wpsp_content', - 'label' => esc_html__( 'List type', 'wp-show-posts' ), - 'choices' => array( - 'ordered' => __( 'Ordered','wp-show-posts' ), - 'unordered' => __( 'Unordered','wp-show-posts' ), - 'none' => __( 'None','wp-show-posts' ) - ), - 'attr' => array( 'id' => 'wpsp-list-type' ) - ) - ); - - $manager->register_setting( - 'wpsp_list_type', // Same as control name. - array( - 'sanitize_callback' => 'sanitize_text_field', - 'default' => $defaults[ 'wpsp_list_type' ] ? $defaults[ 'wpsp_list_type' ] : '' - ) - ); - - $manager->register_control( ->>>>>>> Add ability to display posts as a list - 'wpsp_excerpt_length', // Same as setting name. + 'wpsp_excerpt_length', // Same as setting name. array( 'type' => 'number', 'section' => 'wpsp_content', From ef60ffe2095b3369e03ac30563545b985103c979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Humbert?= Date: Tue, 23 Jan 2018 15:56:43 +0100 Subject: [PATCH 04/18] Removed by merge but required --- inc/compat.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ inc/deprecated.php | 10 ++++++++++ inc/styling.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 inc/compat.php create mode 100644 inc/deprecated.php create mode 100644 inc/styling.php diff --git a/inc/compat.php b/inc/compat.php new file mode 100644 index 0000000..80f58bb --- /dev/null +++ b/inc/compat.php @@ -0,0 +1,44 @@ + array( + 'margin-left' => ( '' !== $settings[ 'columns_gutter' ] && '12' !== $settings[ 'columns' ] ) ? '-' . $settings[ 'columns_gutter' ] : null + ), + '.wp-show-posts-columns#wpsp-' . $settings[ 'list_id' ] . ' .wp-show-posts-inner' => array( + 'margin' => ( '' !== $settings[ 'columns_gutter' ] && '12' !== $settings[ 'columns' ] ) ? '0 0 ' . $settings[ 'columns_gutter' ] . ' ' . $settings[ 'columns_gutter' ] : null, + ), + ); + // Output the above CSS + $output = ''; + foreach( $visual_css as $k => $properties ) { + if ( !count( $properties ) ) { + continue; + } + $temporary_output = $k . ' {'; + $elements_added = 0; + foreach( $properties as $p => $v ) { + if ( empty( $v ) ) { + continue; + } + $elements_added++; + $temporary_output .= $p . ': ' . $v . '; '; + } + $temporary_output .= "}"; + if ( $elements_added > 0 ) { + $output .= $temporary_output; + } + } + $output = str_replace(array("\r", "\n"), '', $output); + if ( '' !== $output ) { + echo ''; + } +} From a199b9d8e99435ff7f0e71d7d713a58952282e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Humbert?= Date: Tue, 23 Jan 2018 16:03:36 +0100 Subject: [PATCH 05/18] Removed by merge but required --- css/wp-show-posts-min.css | 1 + 1 file changed, 1 insertion(+) create mode 100644 css/wp-show-posts-min.css diff --git a/css/wp-show-posts-min.css b/css/wp-show-posts-min.css new file mode 100644 index 0000000..116308d --- /dev/null +++ b/css/wp-show-posts-min.css @@ -0,0 +1 @@ +body .wp-show-posts a{box-shadow:0 0 0 transparent}.wp-show-posts-entry-title a{text-decoration:none}a.wp-show-posts-read-more,a.wp-show-posts-read-more:visited{display:inline-block;padding:8px 15px;border:2px solid #222;color:#222;font-size:0.8em;text-decoration:none}.wpsp-read-more{margin:0 0 1em;display:inline-block}a.wp-show-posts-read-more:hover,a.wp-show-posts-read-more:focus{border:2px solid transparent;color:#fff;background:#222;text-decoration:none}.wp-show-posts-image{margin-bottom:1em}.wp-show-posts-image.wpsp-image-left{float:left;margin-right:1.5em}.wp-show-posts-image.wpsp-image-right{float:right;margin-left:1.5em}.wp-show-posts-image.wpsp-image-center{display:block;text-align:center}.wp-show-posts-image img{margin:0 !important;vertical-align:bottom;height:auto}.wp-show-posts-entry-header{margin:0 0 1em;padding:0}.wp-show-posts .wp-show-posts-entry-title{font-size:30px;line-height:1.5em;margin:0}.wp-show-posts-updated{display:none}.wp-show-posts-entry-summary,.wp-show-posts-entry-content{margin-bottom:1em}.wp-show-posts-entry-meta{font-size:0.8em}.wp-show-posts-separator{opacity:0.5}.wp-show-posts-meta a,.wp-show-posts-meta a:visited{color:rgba( 0,0,0,0.5 )}.stack-wp-show-posts-byline,.stack-wp-show-posts-posted-on{display:block}.wp-show-posts-entry-meta-below-post{margin-bottom:1em}.wp-show-posts-columns:not(.wp-show-posts-masonry){display:flex;flex-wrap:wrap}.wp-show-posts-columns .wp-show-posts-single:not(.wp-show-posts-masonry-block){display:flex;flex-direction:row}.wp-show-posts-columns .wp-show-posts-single:not(.wp-show-posts-masonry-block) .wp-show-posts-image img{flex:0 0 auto;object-fit:scale-down}.wpsp-clear{clear:both;display:block;overflow:hidden;visibility:hidden;width:0;height:0}.wp-show-posts:not(.wp-show-posts-columns) .wp-show-posts-single:not(:last-child){margin-bottom:2em}.wpsp-load-more{margin-top:2em}.wp-show-posts-columns .wp-show-posts-entry-title{font-size:25px}.wp-show-posts-columns .wp-show-posts-single.col-md-4 .wp-show-posts-entry-title,.wp-show-posts-columns .wp-show-posts-single.col-md-3 .wp-show-posts-entry-title,.wp-show-posts-columns .wp-show-posts-single.col-md-20 .wp-show-posts-entry-title{font-size:20px}.wp-show-posts-columns .wp-show-posts-inner{flex:1}.wp-show-posts-inner:after{clear:both;display:table;content:'';width:0;height:0;overflow:hidden;visibility:hidden}.wp-show-posts-single.post {margin-bottom: 0;}@media (min-width: 768px){.wpsp-col-1,.wpsp-col-2,.wpsp-col-3,.wpsp-col-4,.wpsp-col-5,.wpsp-col-6,.wpsp-col-7,.wpsp-col-8,.wpsp-col-9,.wpsp-col-10,.wpsp-col-11,.wpsp-col-12,.wpsp-col-20{float:left}.wpsp-col-1{width:8.333333%}.wpsp-col-2{width:16.666667%}.wpsp-col-3{width:25%}.wpsp-col-4{width:33.333%}.wpsp-col-5{width:41.666667%}.wpsp-col-6{width:50%}.wpsp-col-7{width:58.333333%}.wpsp-col-8{width:66.666667%}.wpsp-col-9{width:75%}.wpsp-col-10{width:83.333333%}.wpsp-col-11{width:91.666667%}.wpsp-col-12{width:100%}.wpsp-col-20{width:20%}}@media (max-width: 767px){.wp-show-posts-columns,.wp-show-posts-inner{margin-left:0 !important;margin-right:0 !important}.wp-show-posts-columns .wp-show-posts-single{display:block;width:100%}.wp-show-posts-image.wpsp-image-left,.wp-show-posts-image.wpsp-image-right{float:none;margin-right:0;margin-left:0}}.wp-show-posts-inner *:last-child{margin-bottom:0}.screen-reader-text{clip:rect(1px, 1px, 1px, 1px);position:absolute !important}.screen-reader-text:hover,.screen-reader-text:active,.screen-reader-text:focus{background-color:#f1f1f1;border-radius:3px;box-shadow:0 0 2px 2px rgba(0, 0, 0, 0.6);clip:auto !important;color:#21759b;display:block;font-size:14px;font-weight:bold;height:auto;left:5px;line-height:normal;padding:15px 23px 14px;text-decoration:none;top:5px;width:auto;z-index:100000}.wpsp-clearfix:after{content:".";display:block;overflow:hidden;visibility:hidden;font-size:0;line-height:0;width:0;height:0} From 1079e38f879166fc5c05e6f9399b441ea657c9ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Humbert?= Date: Tue, 23 Jan 2018 16:17:50 +0100 Subject: [PATCH 06/18] beautifullage --- admin/metabox.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/admin/metabox.php b/admin/metabox.php index ffc082e..1e73d7f 100644 --- a/admin/metabox.php +++ b/admin/metabox.php @@ -389,6 +389,29 @@ function wpsp_register( $butterbean, $post_type ) { ) ); + $manager->register_control( + 'wpsp_list_type', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_content', + 'label' => esc_html__( 'List type', 'wp-show-posts' ), + 'choices' => array( + 'ordered' => __( 'Ordered','wp-show-posts' ), + 'unordered' => __( 'Unordered','wp-show-posts' ), + 'none' => __( 'None','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-list-type' ) + ) + ); + + $manager->register_setting( + 'wpsp_list_type', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_list_type' ] ? $defaults[ 'wpsp_list_type' ] : 'none' + ) + ); + $manager->register_control( 'wpsp_excerpt_length', // Same as setting name. array( From e1cb837a09f6fab133e6ec504055f23db8e3fec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Humbert?= Date: Tue, 30 Jan 2018 13:00:58 +0100 Subject: [PATCH 07/18] Added wpsp_in_text_link --- inc/defaults.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inc/defaults.php b/inc/defaults.php index 5605ca6..989e570 100644 --- a/inc/defaults.php +++ b/inc/defaults.php @@ -48,7 +48,8 @@ function wpsp_get_defaults() { 'wpsp_post_status' => 'publish', 'wpsp_post_type' => 'post', 'wpsp_posts_per_page' => 10, - 'wpsp_read_more_text' => '', + 'wpsp_read_more_text' => '', + 'wpsp_in_text_link' => '', 'wpsp_tax_operator' => 'IN', 'wpsp_tax_term' => '', 'wpsp_taxonomy' => 'category', From a30f944cd3ecb116997d088813ad2f9c8a0eda72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Humbert?= Date: Tue, 30 Jan 2018 13:02:16 +0100 Subject: [PATCH 08/18] Replaced all tabs by spaces for universal alignment --- inc/defaults.php | 118 +++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/inc/defaults.php b/inc/defaults.php index 989e570..8edd971 100644 --- a/inc/defaults.php +++ b/inc/defaults.php @@ -3,64 +3,64 @@ if ( ! defined( 'ABSPATH' ) ) exit; if ( ! function_exists( 'wpsp_get_defaults' ) ) { - /** - * Set all of our defaults - * @since 0.1 - */ - function wpsp_get_defaults() { - $defaults = array( - 'wpsp_author' => '', - 'wpsp_author_location' => 'below-post', - 'wpsp_columns' => 'col-6', - 'wpsp_columns_gutter' => '2em', - 'wpsp_content_type' => 'excerpt', - 'wpsp_list_type' => 'none', - 'wpsp_date_location' => 'below-title', - 'wpsp_exclude_current' => false, - 'wpsp_excerpt_length' => 30, - 'wpsp_post_id' => '', - 'wpsp_exclude_post_id' => '', - 'wpsp_ignore_sticky_posts' => false, - 'wpsp_image' => true, - 'wpsp_image_alignment' => 'center', - 'wpsp_image_height' => '', - 'wpsp_image_location' => 'below-title', - 'wpsp_image_width' => '', - 'wpsp_include_title' => true, - 'wpsp_title_element' => 'h2', - 'wpsp_include_terms' => false, - 'wpsp_include_author' => false, - 'wpsp_include_date' => true, - 'wpsp_include_comments' => false, - 'wpsp_comments_location' => 'below-post', - 'wpsp_inner_wrapper' => 'article', - 'wpsp_inner_wrapper_class' => '', - 'wpsp_inner_wrapper_style' => '', - 'wpsp_itemtype' => 'CreativeWork', - 'wpsp_meta_key' => '', - 'wpsp_meta_value' => '', - 'wpsp_offset' => 0, - 'wpsp_order' => 'DESC', - 'wpsp_orderby' => 'date', - 'wpsp_pagination' => false, - 'wpsp_post_meta_bottom_style' => 'stack', - 'wpsp_post_meta_top_style' => 'inline', - 'wpsp_post_status' => 'publish', - 'wpsp_post_type' => 'post', - 'wpsp_posts_per_page' => 10, - 'wpsp_read_more_text' => '', - 'wpsp_in_text_link' => '', - 'wpsp_tax_operator' => 'IN', - 'wpsp_tax_term' => '', - 'wpsp_taxonomy' => 'category', - 'wpsp_terms_location' => 'below-post', - 'wpsp_wrapper' => 'section', - 'wpsp_wrapper_class' => '', - 'wpsp_wrapper_id' => false, - 'wpsp_wrapper_style' => '', - 'wpsp_no_results' => __( 'Sorry, no posts were found.','wp-show-posts' ) - ); + /** + * Set all of our defaults + * @since 0.1 + */ + function wpsp_get_defaults() { + $defaults = array( + 'wpsp_author' => '', + 'wpsp_author_location' => 'below-post', + 'wpsp_columns' => 'col-6', + 'wpsp_columns_gutter' => '2em', + 'wpsp_content_type' => 'excerpt', + 'wpsp_list_type' => 'none', + 'wpsp_date_location' => 'below-title', + 'wpsp_exclude_current' => false, + 'wpsp_excerpt_length' => 30, + 'wpsp_post_id' => '', + 'wpsp_exclude_post_id' => '', + 'wpsp_ignore_sticky_posts' => false, + 'wpsp_image' => true, + 'wpsp_image_alignment' => 'center', + 'wpsp_image_height' => '', + 'wpsp_image_location' => 'below-title', + 'wpsp_image_width' => '', + 'wpsp_include_title' => true, + 'wpsp_title_element' => 'h2', + 'wpsp_include_terms' => false, + 'wpsp_include_author' => false, + 'wpsp_include_date' => true, + 'wpsp_include_comments' => false, + 'wpsp_comments_location' => 'below-post', + 'wpsp_inner_wrapper' => 'article', + 'wpsp_inner_wrapper_class' => '', + 'wpsp_inner_wrapper_style' => '', + 'wpsp_itemtype' => 'CreativeWork', + 'wpsp_meta_key' => '', + 'wpsp_meta_value' => '', + 'wpsp_offset' => 0, + 'wpsp_order' => 'DESC', + 'wpsp_orderby' => 'date', + 'wpsp_pagination' => false, + 'wpsp_post_meta_bottom_style' => 'stack', + 'wpsp_post_meta_top_style' => 'inline', + 'wpsp_post_status' => 'publish', + 'wpsp_post_type' => 'post', + 'wpsp_posts_per_page' => 10, + 'wpsp_read_more_text' => '', + 'wpsp_in_text_link' => '', + 'wpsp_tax_operator' => 'IN', + 'wpsp_tax_term' => '', + 'wpsp_taxonomy' => 'category', + 'wpsp_terms_location' => 'below-post', + 'wpsp_wrapper' => 'section', + 'wpsp_wrapper_class' => '', + 'wpsp_wrapper_id' => false, + 'wpsp_wrapper_style' => '', + 'wpsp_no_results' => __( 'Sorry, no posts were found.','wp-show-posts' ) + ); - return apply_filters( 'wpsp_defaults', $defaults ); - } + return apply_filters( 'wpsp_defaults', $defaults ); + } } From cfb89ff9aac12a5433c33856e1f2d99c13861ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Humbert?= Date: Tue, 30 Jan 2018 13:09:26 +0100 Subject: [PATCH 09/18] Working --- admin/metabox.php | 17 +++++++++++++++++ inc/functions.php | 15 +++++++++++++++ wp-show-posts.php | 21 +++++++++++++++++++-- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/admin/metabox.php b/admin/metabox.php index 1e73d7f..07641c7 100644 --- a/admin/metabox.php +++ b/admin/metabox.php @@ -494,6 +494,23 @@ function wpsp_register( $butterbean, $post_type ) { ) ); + $manager->register_control( + 'wpsp_in_text_link', // Same as setting name. + array( + 'type' => 'text', + 'section' => 'wpsp_content', + 'label' => esc_html__( 'In text link', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_in_text_link', // Same as control name. + array( + 'sanitize_callback' => 'wp_kses_post', + 'default' => $defaults[ 'wpsp_in_text_link' ] ? $defaults[ 'wpsp_in_text_link' ] : '' + ) + ); + $manager->register_section( 'wpsp_post_meta', array( diff --git a/inc/functions.php b/inc/functions.php index 71e8f74..9a43354 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -37,6 +37,21 @@ function wpsp_excerpt() { } } +if ( ! function_exists( 'wpsp_get_the_excerpt' ) ) { + /** + * Build our excerpt + * @since 0.9 + */ + function wpsp_get_the_excerpt() { + add_filter( 'excerpt_length', 'wpsp_excerpt_length', 999 ); + add_filter( 'excerpt_more', 'wpsp_excerpt_more', 999 ); + $excerpt = get_the_excerpt(); + remove_filter( 'excerpt_length', 'wpsp_excerpt_length', 999 ); + remove_filter( 'excerpt_more', 'wpsp_excerpt_more', 999 ); + return $excerpt; + } +} + if ( ! function_exists( 'wpsp_meta' ) ) { /** * Build our post meta. diff --git a/wp-show-posts.php b/wp-show-posts.php index 3d5bd22..b1d4995 100644 --- a/wp-show-posts.php +++ b/wp-show-posts.php @@ -137,6 +137,7 @@ function wpsp_display( $id, $custom_settings = false ) { 'tax_term' => wpsp_get_setting( $id, 'wpsp_tax_term' ), 'taxonomy' => sanitize_key( wpsp_get_setting( $id, 'wpsp_taxonomy' ) ), 'read_more_text' => wp_kses_post( wpsp_get_setting( $id, 'wpsp_read_more_text' ) ), + 'in_text_link' => wp_kses_post( wpsp_get_setting( $id, 'wpsp_in_text_link' ) ), 'wrapper' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_wrapper' ) ), 'wrapper_class' => array_map( 'sanitize_html_class', ( explode( ' ', wpsp_get_setting( $id, 'wpsp_wrapper_class' ) ) ) ), 'wrapper_style' => explode( ' ', esc_attr( wpsp_get_setting( $id, 'wpsp_wrapper_style' ) ) ), @@ -462,14 +463,30 @@ function wpsp_display( $id, $custom_settings = false ) { global $post; $more_tag = apply_filters( 'wpsp_more_tag', strpos( $post->post_content, '' ) ); + // Compose text output + if (!empty($settings[ 'in_text_link' ])) { + $permalink = get_permalink(); + if ('excerpt' == $settings['content_type']) { + $output = wpsp_get_the_excerpt() . " " . $settings['in_text_link'] . ""; + } elseif ('full' == $settings['content_type']) { + $output = get_the_content() . " " . $settings['in_text_link'] . ""; + } + } else { + if ('excerpt' == $settings['content_type']) { + $output = wpsp_get_the_excerpt(); + } elseif ('full' == $settings['content_type']) { + $output = get_the_content(); + } + } + // The excerpt or full content if ( 'excerpt' == $settings[ 'content_type' ] && $settings[ 'excerpt_length' ] && ! $more_tag && 'none' !== $settings[ 'content_type' ] ) : ?>
    - +
    - +
    Date: Tue, 30 Jan 2018 13:11:51 +0100 Subject: [PATCH 10/18] Features update --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index 9c92344..8468381 100644 --- a/readme.txt +++ b/readme.txt @@ -50,6 +50,7 @@ Here are the features in the free version: * Excerpt length * Include title * Read more text +* In-text link to post = Meta = From 2dc400746e6ff00495bf062dd6041677aa0b47b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Humbert?= Date: Tue, 30 Jan 2018 17:45:54 +0100 Subject: [PATCH 11/18] Meta option edit link working --- admin/js/admin-scripts.js | 13 +++++++++++++ admin/metabox.php | 40 +++++++++++++++++++++++++++++++++++++++ inc/defaults.php | 1 + inc/functions.php | 28 ++++++++++++++++++++++++--- wp-show-posts.php | 2 ++ 5 files changed, 81 insertions(+), 3 deletions(-) diff --git a/admin/js/admin-scripts.js b/admin/js/admin-scripts.js index 16ed25f..bd0d5cf 100644 --- a/admin/js/admin-scripts.js +++ b/admin/js/admin-scripts.js @@ -225,6 +225,19 @@ jQuery( document ).ready( function( $ ) { } }); + // Edit link location + if ( ! $( '#wpsp-include-edit-link' ).is( ':checked' ) ) { + $( '#butterbean-control-wpsp_edit_link_location' ).hide(); + } + + $( '#wpsp-include-edit-link' ).change(function() { + if ( ! this.checked ) { + $( '#butterbean-control-wpsp_edit_link_location' ).hide(); + } else { + $( '#butterbean-control-wpsp_edit_link_location' ).show(); + } + }); + // Dealing with the social options $( '#wpsp-social-sharing' ).parent().parent().siblings().hide(); if ( $( '#wpsp-social-sharing' ).is( ':checked' ) ) { diff --git a/admin/metabox.php b/admin/metabox.php index 07641c7..1a2a50d 100644 --- a/admin/metabox.php +++ b/admin/metabox.php @@ -639,6 +639,46 @@ function wpsp_register( $butterbean, $post_type ) { ) ); + $manager->register_control( + 'wpsp_include_edit_link', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_post_meta', + 'label' => __( 'Include edit link (only admins will see it)','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-include-edit-link' ) + ) + ); + + $manager->register_setting( + 'wpsp_include_edit_link', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_include_edit_link' ] ? $defaults[ 'wpsp_include_edit_link' ] : false + ) + ); + + $manager->register_control( + 'wpsp_edit_link_location', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_post_meta', + 'label' => esc_html__( 'Edit link location', 'wp-show-posts' ), + 'choices' => array( + 'below-title' => __( 'Below title','wp-show-posts' ), + 'below-post' => __( 'Below post','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-edit-link-location' ) + ) + ); + + $manager->register_setting( + 'wpsp_edit_link_location', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_edit_link_location' ] ? $defaults[ 'wpsp_edit_link_location' ] : '' + ) + ); + $manager->register_control( 'wpsp_include_comments', array( diff --git a/inc/defaults.php b/inc/defaults.php index 8edd971..83aa058 100644 --- a/inc/defaults.php +++ b/inc/defaults.php @@ -31,6 +31,7 @@ function wpsp_get_defaults() { 'wpsp_include_terms' => false, 'wpsp_include_author' => false, 'wpsp_include_date' => true, + 'wpsp_include_edit_link' => false, 'wpsp_include_comments' => false, 'wpsp_comments_location' => 'below-post', 'wpsp_inner_wrapper' => 'article', diff --git a/inc/functions.php b/inc/functions.php index 9a43354..19f574f 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -67,10 +67,22 @@ function wpsp_meta( $location, $settings ) { $post_meta_style = $settings[ 'post_meta_top_style' ]; } - if ( ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && $location == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && $location == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && $location == $settings[ 'comments_location' ] ) ) { + if ( ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) + || ( $settings[ 'include_date' ] && $location == $settings[ 'date_location' ] ) + || ( $settings[ 'include_terms' ] && $location == $settings[ 'terms_location' ] ) + || ( $settings[ 'include_comments' ] && $location == $settings[ 'comments_location' ] ) + || ( $settings[ 'include_edit_link'] && $location == $settings[ 'edit_link_location' ] ) + ) { echo '