Skip to content

Commit

Permalink
Merge branch 'release/1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Croft committed Sep 4, 2017
2 parents d9d848a + b9029a6 commit e6d4486
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 13 deletions.
79 changes: 79 additions & 0 deletions lib/classes/class.Genesis_Portolio_Archive_Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

class Genesis_Portolio_Archive_Settings {

var $settings_field;

/**
* Callback on the `genesis_cpt_archives_settings_metaboxes` action.
* Checks to see if this is the correct page, then instatiates the object.
*
* @access public
* @static
* @param string $pagehook
* @return void
*/
static function register_metaboxes( $pagehook ) {

if ( 'portfolio_page_genesis-cpt-archive-portfolio' !== $pagehook ) {
return;
}

new static( $pagehook );

}

/**
* Builds the HTML output for the portfolio archive settings.
*
* @access public
* @param mixed $pagehook
* @return void
*/
function __construct( $pagehook ) {

$this->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( '<table class="form-table"><tbody>
<tr valign="top">
<th scope="row"><label for="%1$s-%2$s"><b>%3$s</b></label></th>
<td><input name="%1$s[%2$s]" type="number" step="1" min="1" id="%1$s-%2$s" value="%5$s" class="small-text">%4$s</td>
</tr>
</tbody></table>',
$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]
);

}

}
2 changes: 1 addition & 1 deletion lib/templates/taxonomy-portfolio-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
112 changes: 103 additions & 9 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Plugin Name: Genesis Portfolio Pro
Plugin URI:
Description: Adds default portfolio to any Genesis HTML5 theme.
Version: 1.0.1
Author: copyblogger
Author URI: http://www.copyblogger.com
Version: 1.1
Author: StudioPress
Author URI: http://www.studiopress.com
Text Domain: genesis-portfolio-pro
Domain Path: /languages
Expand All @@ -23,17 +23,37 @@
*
* @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__ ) );
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' );
/**
Expand All @@ -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' );

}

Expand Down Expand Up @@ -85,7 +110,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;

Expand All @@ -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
Expand Down Expand Up @@ -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_post_type_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'] ) );

}
14 changes: 11 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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.

Expand All @@ -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.

0 comments on commit e6d4486

Please sign in to comment.