From 2cc25eb8d49293e3f77f9da1af6765ee836614f3 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Tue, 15 Aug 2017 10:19:33 -0400 Subject: [PATCH 1/8] changes logic for term meta layout check addresses https://github.com/copyblogger/genesis-portfolio-pro/issues/18 --- lib/templates/taxonomy-portfolio-type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/templates/taxonomy-portfolio-type.php b/lib/templates/taxonomy-portfolio-type.php index 1256cca..3e117aa 100644 --- a/lib/templates/taxonomy-portfolio-type.php +++ b/lib/templates/taxonomy-portfolio-type.php @@ -21,7 +21,7 @@ function genesis_portfolio_taxonomy_template_layout( $layout ) { global $wp_query; $term = $wp_query->get_queried_object(); - $layout = $term && isset( $term->meta['layout'] ) && $term->meta['layout'] ? $term->meta['layout'] : __genesis_return_full_width_content(); + $layout = $term && isset( $term->term_id ) && $opt = get_term_meta( $term->term_id, 'layout', true ) ? $opt : __genesis_return_full_width_content(); return $layout; From 70db9bca42bf300aaa5469d9ba26bbc0532a090f Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Tue, 15 Aug 2017 10:22:45 -0400 Subject: [PATCH 2/8] Changes plugin attribution to StudioPress addresses #14 --- plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.php b/plugin.php index 5e7488c..3e5e591 100644 --- a/plugin.php +++ b/plugin.php @@ -4,8 +4,8 @@ Plugin URI: Description: Adds default portfolio to any Genesis HTML5 theme. Version: 1.0.1 - Author: copyblogger - Author URI: http://www.copyblogger.com + Author: studiopress + Author URI: http://www.studiopress.com Text Domain: genesis-portfolio-pro Domain Path: /languages From 09aa3e3072e64b9ae1fb30cea0028d2a95db99fd Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Tue, 15 Aug 2017 10:22:55 -0400 Subject: [PATCH 3/8] cost standard improvements --- plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.php b/plugin.php index 3e5e591..f301b4e 100644 --- a/plugin.php +++ b/plugin.php @@ -33,7 +33,7 @@ function genesis_portfolio_load_plugin_textdomain() { define( 'GENESIS_PORTFOLIO_LIB', dirname( __FILE__ ) . '/lib/' ); -define( 'GENESIS_PORTFOLIO_URL', plugins_url( '/', __FILE__ ) ); +define( 'GENESIS_PORTFOLIO_URL', plugins_url( '/', __FILE__ ) ); add_action( 'genesis_init', 'genesis_portfolio_init' ); /** @@ -85,7 +85,7 @@ function genesis_portfolio_load_admin_styles() { * @since 0.1.0 * */ -function genesis_portfolio_after_setup_theme(){ +function genesis_portfolio_after_setup_theme() { global $_wp_additional_image_sizes; From 50d570617a68e218e70202611b4114b9e2d6c084 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Tue, 15 Aug 2017 16:38:20 -0400 Subject: [PATCH 4/8] adds post per page option to archive settings addresses #6 --- ...lass.Genesis_Portolio_Archive_Settings.php | 79 ++++++++++++++ plugin.php | 102 +++++++++++++++++- 2 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 lib/classes/class.Genesis_Portolio_Archive_Settings.php diff --git a/lib/classes/class.Genesis_Portolio_Archive_Settings.php b/lib/classes/class.Genesis_Portolio_Archive_Settings.php new file mode 100644 index 0000000..0fec50e --- /dev/null +++ b/lib/classes/class.Genesis_Portolio_Archive_Settings.php @@ -0,0 +1,79 @@ +settings_field = GENESIS_CPT_ARCHIVE_SETTINGS_FIELD_PREFIX . 'portfolio'; + + add_meta_box( 'post_per_page', __( 'Items Per Page', 'genesis-portfolio-pro' ), array( $this, 'posts_per_page_metabox' ), $pagehook, 'main', 'low' ); + + } + + /** + * Callback for the posts_per_page metabox. + * Outputs the settings for the posts per page in the archives + * + * @access public + * @return void + */ + function posts_per_page_metabox() { + echo $this->get_post_per_page_setting(); + } + + /** + * Gets the posts per page setting HTML markup. + * + * @access public + * @return string + */ + function get_post_per_page_setting() { + + $opts = (array) get_option( $this->settings_field ); + + $key = 'posts_per_page'; + + return sprintf( ' + + + + +
%4$s
', + $this->settings_field, + $key, + __( 'Archives show at most', 'genesis-portfolio-pro' ), + __( ' portfolio items' , 'genesis-portfolio-pro' ), + empty( $opts[$key] ) ? get_option( 'posts_per_page' ) : $opts[$key] + ); + + } + +} diff --git a/plugin.php b/plugin.php index f301b4e..411b226 100644 --- a/plugin.php +++ b/plugin.php @@ -23,18 +23,38 @@ * * @uses load_plugin_textdomain() * @since 1.0.0 - * + * * @access public * @return void */ function genesis_portfolio_load_plugin_textdomain() { - load_plugin_textdomain( 'genesis-portfolio-pro', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' ); + load_plugin_textdomain( 'genesis-portfolio-pro', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' ); } - define( 'GENESIS_PORTFOLIO_LIB', dirname( __FILE__ ) . '/lib/' ); define( 'GENESIS_PORTFOLIO_URL', plugins_url( '/', __FILE__ ) ); +spl_autoload_register( 'genesis_portfolio_autoload' ); +/** + * Callback for the `spl_autoload_register` function. + * Requires class files for specified classes. + * + * @access public + * @param string $class + * @return void + */ +function genesis_portfolio_autoload( $class ) { + + $classes = array( + 'Genesis_Portolio_Archive_Settings', + ); + + if ( in_array( $class, $classes ) ) { + require sprintf( '%s/classes/class.%s.php', GENESIS_PORTFOLIO_LIB, $class ); + } + +} + add_action( 'genesis_init', 'genesis_portfolio_init' ); /** * Init action loads required files and other actions. @@ -56,7 +76,12 @@ function genesis_portfolio_init() { require_once( GENESIS_PORTFOLIO_LIB . 'template-loader.php' ); } - add_action( 'after_setup_theme', 'genesis_portfolio_after_setup_theme' ); + //archive settings + add_action( 'genesis_cpt_archives_settings_metaboxes', array( 'Genesis_Portolio_Archive_Settings', 'register_metaboxes' ) ); + + add_action( 'genesis_settings_sanitizer_init' , 'genesis_portfolio_archive_setting_sanitization' ); + add_action( 'genesis_cpt_archive_settings_defaults', 'genesis_portfolio_archive_setting_defaults' , 10, 2 ); + add_action( 'after_setup_theme' , 'genesis_portfolio_after_setup_theme' ); } @@ -95,6 +120,46 @@ function genesis_portfolio_after_setup_theme() { } +/** + * Callback on the `genesis_settings_sanitizer_init` hook. + * Registers the sanitize method for the posts_per_page archive setting option + * + * @access public + * @static + * @return void + */ +function genesis_portfolio_archive_setting_sanitization() { + + genesis_add_option_filter( + 'absint', + GENESIS_CPT_ARCHIVE_SETTINGS_FIELD_PREFIX . 'portfolio', + array( + 'posts_per_page', + ) + ); + +} + +/** + * Callback on the `genesis_cpt_archive_settings_defaults` filter. + * Adds the archive setting for pagination + * + * @access public + * @param array $defaults + * @param string $post_type + * @return array + */ +function genesis_portfolio_archive_setting_defaults( $defaults = array(), $post_type ) { + + if ( 'portfolio' === $post_type ) { + $defaults = (array) $defaults; + $defaults['posts_per_page'] = get_option( 'posts_per_page' ); + } + + return $defaults; + +} + register_activation_hook( __FILE__, 'genesis_portfolio_rewrite_flush' ); /** * Activation hook action to flush the rewrit rules for the custom post type and taxonomy @@ -150,3 +215,32 @@ function genesis_portfolio_remove_entry_actions( $action ) { genesis_portfolio_remove_actions( $action, $hooks ); } + +add_filter( 'pre_get_posts', 'genesis_portfolio_archive_pre_get_posts', 999 ); +/** + * Callback on the pre_get_posts hook. + * Changes the posts per page setting for portfolio and portfolio-type archives if set. + * + * @access public + * @param obj $query + * @return void + */ +function genesis_portfolio_archive_pre_get_posts( $query ) { + + if ( ! $query->is_main_query() ) { + return; + } + + if ( ! $query->is_archive( 'portfolio' ) && ! $query->is_tax( 'portfolio-type' ) ) { + return; + } + + $opts = (array) get_option( GENESIS_CPT_ARCHIVE_SETTINGS_FIELD_PREFIX . 'portfolio' ); + + if ( empty( $opts['posts_per_page'] ) ) { + return; + } + + $query->set( 'posts_per_page', intval( $opts['posts_per_page'] ) ); + +} From a3b569eac27dcb748235df9107b01c49aef44af6 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Tue, 15 Aug 2017 20:13:27 -0400 Subject: [PATCH 5/8] updates version details for release --- plugin.php | 2 +- readme.txt | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugin.php b/plugin.php index 411b226..51a58e8 100644 --- a/plugin.php +++ b/plugin.php @@ -3,7 +3,7 @@ Plugin Name: Genesis Portfolio Pro Plugin URI: Description: Adds default portfolio to any Genesis HTML5 theme. - Version: 1.0.1 + Version: 1.1 Author: studiopress Author URI: http://www.studiopress.com Text Domain: genesis-portfolio-pro diff --git a/readme.txt b/readme.txt index 71d3d43..5b109f0 100644 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,9 @@ === Genesis Portfolio Pro === Contributors: nathanrice, studiopress, wpmuguru, nick_thegeek, bgardner Tags: genesis, portfolio, templates -Requires at least: 3.7 -Tested up to: 4.7.4 -Stable tag: 1.0.1 +Requires at least: 4.4 +Tested up to: 4.8.1 +Stable tag: 1.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -30,6 +30,10 @@ Custom templates are supported using the WordPress template hierarchy and the po == Changelog == += 1.1 = +* Added Feature items per page in portfolio archive settings +* Fix layout setting for portfolio-type term + = 1.0.1 = * Bug fix for search layout. @@ -38,5 +42,9 @@ Custom templates are supported using the WordPress template hierarchy and the po == Upgrade Notice == += 1.1 = + +Portfolio-Type term meta layout setting now working. If this was changed for a term it will take effect on upgrade. Users should check their portfolio-type archives to ensure the desired layout is displayed. + = 1.0 = Plugin was added to the WordPress.org repo. Users should update to ensure they have the latest code. From ba6d99e5e55d52650566b3a9b5f8185c3c727c2b Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Thu, 24 Aug 2017 08:04:49 -0400 Subject: [PATCH 6/8] change studiopress to StudioPress addresses #14 --- plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.php b/plugin.php index 51a58e8..5c13eb6 100644 --- a/plugin.php +++ b/plugin.php @@ -4,7 +4,7 @@ Plugin URI: Description: Adds default portfolio to any Genesis HTML5 theme. Version: 1.1 - Author: studiopress + Author: StudioPress Author URI: http://www.studiopress.com Text Domain: genesis-portfolio-pro Domain Path: /languages From d8f138c23ee1d2db70065897ef1d335133648844 Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Thu, 24 Aug 2017 08:06:07 -0400 Subject: [PATCH 7/8] adds brackets for ternary addresses #18 --- lib/templates/taxonomy-portfolio-type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/templates/taxonomy-portfolio-type.php b/lib/templates/taxonomy-portfolio-type.php index 3e117aa..a7858eb 100644 --- a/lib/templates/taxonomy-portfolio-type.php +++ b/lib/templates/taxonomy-portfolio-type.php @@ -21,7 +21,7 @@ function genesis_portfolio_taxonomy_template_layout( $layout ) { global $wp_query; $term = $wp_query->get_queried_object(); - $layout = $term && isset( $term->term_id ) && $opt = get_term_meta( $term->term_id, 'layout', true ) ? $opt : __genesis_return_full_width_content(); + $layout = ( $term && isset( $term->term_id ) && $opt = get_term_meta( $term->term_id, 'layout', true ) ) ? $opt : __genesis_return_full_width_content(); return $layout; From b9029a6f36577d4e951c24d678bc2032c392f23a Mon Sep 17 00:00:00 2001 From: Nick Croft Date: Thu, 24 Aug 2017 08:06:47 -0400 Subject: [PATCH 8/8] switches to is_post_type_archive addresses #6 --- plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.php b/plugin.php index 5c13eb6..c0bd5b8 100644 --- a/plugin.php +++ b/plugin.php @@ -231,7 +231,7 @@ function genesis_portfolio_archive_pre_get_posts( $query ) { return; } - if ( ! $query->is_archive( 'portfolio' ) && ! $query->is_tax( 'portfolio-type' ) ) { + if ( ! $query->is_post_type_archive( 'portfolio' ) && ! $query->is_tax( 'portfolio-type' ) ) { return; }