Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions admin/js/admin-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,32 @@ 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();
}
});

// Add item location
if ( ! $( '#wpsp-include-add-item' ).is( ':checked' ) ) {
$( '#butterbean-control-wpsp_add_item_location' ).hide();
}

$( '#wpsp-include-add-item' ).change(function() {
if ( ! this.checked ) {
$( '#butterbean-control-wpsp_add_item_location' ).hide();
} else {
$( '#butterbean-control-wpsp_add_item_location' ).show();
}
});

// Dealing with the social options
$( '#wpsp-social-sharing' ).parent().parent().siblings().hide();
if ( $( '#wpsp-social-sharing' ).is( ':checked' ) ) {
Expand Down
122 changes: 121 additions & 1 deletion admin/metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,31 @@ 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.
'wpsp_excerpt_length', // Same as setting name.
array(
'type' => 'number',
'section' => 'wpsp_content',
Expand Down Expand Up @@ -471,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(
Expand Down Expand Up @@ -599,6 +639,86 @@ 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_add_item',
array(
'type' => 'checkbox',
'section' => 'wpsp_post_meta',
'label' => __( 'Include add item link (only admins will see it)','wp-show-posts' ),
'attr' => array( 'id' => 'wpsp-include-add-item' )
)
);

$manager->register_setting(
'wpsp_include_add_item',
array(
'sanitize_callback' => 'butterbean_validate_boolean',
'default' => $defaults[ 'wpsp_include_add_item' ] ? $defaults[ 'wpsp_include_add_item' ] : false
)
);

$manager->register_control(
'wpsp_add_item_location', // Same as setting name.
array(
'type' => 'select',
'section' => 'wpsp_post_meta',
'label' => esc_html__( 'Add item location', 'wp-show-posts' ),
'choices' => array(
'right' => __( 'Upper right','wp-show-posts' ),
'left' => __( 'Upper left','wp-show-posts' )
),
'attr' => array( 'id' => 'wpsp-edit-link-location' )
)
);

$manager->register_setting(
'wpsp_add_item_location', // Same as control name.
array(
'sanitize_callback' => 'sanitize_text_field',
'default' => $defaults[ 'wpsp_add_item_location' ] ? $defaults[ 'wpsp_add_item_location' ] : ''
)
);

$manager->register_control(
'wpsp_include_comments',
array(
Expand Down
4 changes: 1 addition & 3 deletions inc/compat.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
// No direct access, please
if ( ! defined( 'ABSPATH' ) ) exit;

if ( ! function_exists( 'wpsp_pro_defaults' ) ) {
add_filter( 'wpsp_defaults', 'wpsp_pro_compat_defaults' );
/**
Expand Down Expand Up @@ -40,7 +39,6 @@ function wpsp_pro_compat_defaults( $defaults ) {
$defaults[ 'wpsp_link' ] = '';
$defaults[ 'wpsp_link_hover' ] = '';
$defaults[ 'wpsp_padding' ] = '';

return $defaults;
}
}
}
120 changes: 63 additions & 57 deletions inc/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,68 @@
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_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' )
);
/**
* 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_add_item' => false,
'wpsp_add_item_location' => 'below-post',
'wpsp_include_edit_link' => false,
'wpsp_edit_link_location' => 'below-post',
'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 );
}
}
42 changes: 39 additions & 3 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -52,10 +67,21 @@ 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 '<div class="wp-show-posts-entry-meta wp-show-posts-entry-meta-' . $location . ' post-meta-' . $post_meta_style . '">';
}

// If edit link is enabled and user is admin, show it
if ( $settings[ 'include_edit_link' ] && $location == $settings[ 'edit_link_location' ] && current_user_can( 'edit_post' , get_the_ID() ) ) {
$edit_url = get_edit_post_link();
$output[] = "<a class='wp-show-post-meta wpsp-edit-post' href='$edit_url'>Edit</a>";
}

// If our author is enabled, show it
if ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) {
$output[] = apply_filters( 'wpsp_author_output', sprintf(
Expand Down Expand Up @@ -129,7 +155,12 @@ function wpsp_meta( $location, $settings ) {
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' ] ) ) {
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' ] )
|| ( $settings[ 'include_edit_link' ] && 'below-title' == $settings[ 'edit_link_location' ] )
) {
wpsp_meta( 'below-title', $settings );
}

Expand All @@ -139,7 +170,12 @@ function wpsp_add_post_meta_after_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' ] ) ) {
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' ] )
|| ( $settings[ 'include_edit_link' ] && 'below-post' == $settings[ 'edit_link_location' ] )
) {
wpsp_meta( 'below-post', $settings );
}
}
Expand Down
Loading