updated plugin GP Premium
version 1.11.2
This commit is contained in:
@ -1,9 +1,17 @@
|
||||
<?php
|
||||
// No direct access, please
|
||||
/**
|
||||
* This file handles the Display Rule conditions for Elements.
|
||||
*
|
||||
* @package GP Premium
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
exit; // No direct access, please.
|
||||
}
|
||||
|
||||
/**
|
||||
* The conditions class.
|
||||
*/
|
||||
class GeneratePress_Conditions {
|
||||
/**
|
||||
* Instance.
|
||||
@ -17,7 +25,7 @@ class GeneratePress_Conditions {
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self;
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
@ -33,25 +41,28 @@ class GeneratePress_Conditions {
|
||||
public static function get_conditions() {
|
||||
$types = array(
|
||||
'general' => array(
|
||||
'label' => esc_attr__( 'General', 'gp-premium' ),
|
||||
'label' => esc_attr__( 'General', 'gp-premium' ),
|
||||
'locations' => array(
|
||||
'general:site' => esc_attr__( 'Entire Site', 'gp-premium' ),
|
||||
'general:front_page' => esc_attr__( 'Front Page', 'gp-premium' ),
|
||||
'general:blog' => esc_attr__( 'Blog', 'gp-premium' ),
|
||||
'general:singular' => esc_attr__( 'All Singular', 'gp-premium' ),
|
||||
'general:archive' => esc_attr__( 'All Archives', 'gp-premium' ),
|
||||
'general:author' => esc_attr__( 'Author Archives', 'gp-premium' ),
|
||||
'general:date' => esc_attr__( 'Date Archives', 'gp-premium' ),
|
||||
'general:search' => esc_attr__( 'Search Results', 'gp-premium' ),
|
||||
'general:404' => esc_attr__( '404 Template', 'gp-premium' ),
|
||||
)
|
||||
)
|
||||
'general:site' => esc_attr__( 'Entire Site', 'gp-premium' ),
|
||||
'general:front_page' => esc_attr__( 'Front Page', 'gp-premium' ),
|
||||
'general:blog' => esc_attr__( 'Blog', 'gp-premium' ),
|
||||
'general:singular' => esc_attr__( 'All Singular', 'gp-premium' ),
|
||||
'general:archive' => esc_attr__( 'All Archives', 'gp-premium' ),
|
||||
'general:author' => esc_attr__( 'Author Archives', 'gp-premium' ),
|
||||
'general:date' => esc_attr__( 'Date Archives', 'gp-premium' ),
|
||||
'general:search' => esc_attr__( 'Search Results', 'gp-premium' ),
|
||||
'general:404' => esc_attr__( '404 Template', 'gp-premium' ),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Add the post types.
|
||||
$post_types = get_post_types( array(
|
||||
'public' => true,
|
||||
), 'objects' );
|
||||
$post_types = get_post_types(
|
||||
array(
|
||||
'public' => true,
|
||||
),
|
||||
'objects'
|
||||
);
|
||||
|
||||
foreach ( $post_types as $post_type_slug => $post_type ) {
|
||||
|
||||
@ -67,15 +78,17 @@ class GeneratePress_Conditions {
|
||||
$types[ $post_type_slug ] = array(
|
||||
'label' => esc_html( $post_type->labels->name ),
|
||||
'locations' => array(
|
||||
'post:' . $post_type_slug => esc_html( $post_type->labels->singular_name )
|
||||
)
|
||||
'post:' . $post_type_slug => esc_html( $post_type->labels->singular_name ),
|
||||
),
|
||||
);
|
||||
|
||||
// Add the post type archive.
|
||||
if ( 'post' == $post_type_slug || ! empty( $post_type_object->has_archive ) ) {
|
||||
if ( 'post' === $post_type_slug || ! empty( $post_type_object->has_archive ) ) {
|
||||
$types[ $post_type_slug . '_archive' ] = array(
|
||||
/* translators: post type name */
|
||||
'label' => sprintf( esc_html_x( '%s Archives', '%s is a singular post type name', 'gp-premium' ), $post_type->labels->singular_name ),
|
||||
'locations' => array(
|
||||
/* translators: post type name */
|
||||
'archive:' . $post_type_slug => sprintf( esc_html_x( '%s Archive', '%s is a singular post type name', 'gp-premium' ), $post_type->labels->singular_name ),
|
||||
),
|
||||
);
|
||||
@ -88,23 +101,28 @@ class GeneratePress_Conditions {
|
||||
|
||||
$public = $taxonomy->public && $taxonomy->show_ui;
|
||||
|
||||
if ( 'post_format' == $taxonomy_slug ) {
|
||||
if ( 'post_format' === $taxonomy_slug ) {
|
||||
continue;
|
||||
} elseif ( ! apply_filters( 'generate_elements_show_taxonomy', $public, $taxonomy ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$label = str_replace( array(
|
||||
$post_type->labels->name,
|
||||
$post_type->labels->singular_name,
|
||||
), '', $taxonomy->labels->singular_name );
|
||||
$label = str_replace(
|
||||
array(
|
||||
$post_type->labels->name,
|
||||
$post_type->labels->singular_name,
|
||||
),
|
||||
'',
|
||||
$taxonomy->labels->singular_name
|
||||
);
|
||||
|
||||
if ( isset( $types[ $post_type_slug . '_archive' ]['locations'] ) ) {
|
||||
$types[ $post_type_slug . '_archive' ]['locations']['taxonomy:' . $taxonomy_slug] = sprintf( esc_html_x( '%1$s %2$s Archive', '%1$s is post type label. %2$s is taxonomy label.', 'gp-premium' ), $post_type->labels->singular_name, $label );
|
||||
/* translators: '%1$s is post type label. %2$s is taxonomy label. */
|
||||
$types[ $post_type_slug . '_archive' ]['locations'][ 'taxonomy:' . $taxonomy_slug ] = sprintf( esc_html_x( '%1$s %2$s Archive', '%1$s is post type label. %2$s is taxonomy label.', 'gp-premium' ), $post_type->labels->singular_name, $label );
|
||||
}
|
||||
|
||||
if ( isset( $types[ $post_type_slug ]['locations'] ) ) {
|
||||
$types[ $post_type_slug ]['locations'][$post_type_slug . ':taxonomy:' . $taxonomy_slug] = esc_html( $post_type->labels->singular_name . ' ' . $label );
|
||||
$types[ $post_type_slug ]['locations'][ $post_type_slug . ':taxonomy:' . $taxonomy_slug ] = esc_html( $post_type->labels->singular_name . ' ' . $label );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,17 +140,17 @@ class GeneratePress_Conditions {
|
||||
public static function get_user_conditions() {
|
||||
$rules = array(
|
||||
'general' => array(
|
||||
'label' => esc_attr__( 'General', 'gp-premium' ),
|
||||
'label' => esc_attr__( 'General', 'gp-premium' ),
|
||||
'rules' => array(
|
||||
'general:all' => esc_attr__( 'All Users', 'gp-premium' ),
|
||||
'general:logged_in' => esc_attr__( 'Logged In', 'gp-premium' ),
|
||||
'general:logged_out' => esc_attr__( 'Logged Out', 'gp-premium' ),
|
||||
)
|
||||
'general:all' => esc_attr__( 'All Users', 'gp-premium' ),
|
||||
'general:logged_in' => esc_attr__( 'Logged In', 'gp-premium' ),
|
||||
'general:logged_out' => esc_attr__( 'Logged Out', 'gp-premium' ),
|
||||
),
|
||||
),
|
||||
'role' => array(
|
||||
'label' => esc_attr__( 'Roles', 'gp-premium' ),
|
||||
'rules' => array(),
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
$roles = get_editable_roles();
|
||||
@ -207,6 +225,37 @@ class GeneratePress_Conditions {
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_admin() && function_exists( 'get_current_screen' ) ) {
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
if ( isset( $current_screen->is_block_editor ) && $current_screen->is_block_editor ) {
|
||||
$post_id = false;
|
||||
|
||||
if ( isset( $_GET['post'] ) ) { // phpcs:ignore -- Just checking if it's set.
|
||||
$post_id = absint( $_GET['post'] ); // phpcs:ignore -- No data processing going on.
|
||||
}
|
||||
|
||||
if ( $post_id ) {
|
||||
|
||||
// Get the location string.
|
||||
$front_page_id = get_option( 'page_on_front' );
|
||||
$blog_id = get_option( 'page_for_posts' );
|
||||
|
||||
if ( (int) $post_id === (int) $front_page_id ) {
|
||||
$location = 'general:front_page';
|
||||
} elseif ( (int) $post_id === (int) $blog_id ) {
|
||||
$location = 'general:blog';
|
||||
} else {
|
||||
if ( isset( $current_screen->post_type ) ) {
|
||||
$location = 'post:' . $current_screen->post_type;
|
||||
}
|
||||
|
||||
$object = $post_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'rule' => $location,
|
||||
'object' => $object,
|
||||
@ -230,7 +279,7 @@ class GeneratePress_Conditions {
|
||||
|
||||
$user = wp_get_current_user();
|
||||
|
||||
foreach ( ( array ) $user->roles as $role ) {
|
||||
foreach ( (array) $user->roles as $role ) {
|
||||
$status[] = $role;
|
||||
}
|
||||
|
||||
@ -242,6 +291,9 @@ class GeneratePress_Conditions {
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @param array $conditionals The conditions.
|
||||
* @param array $exclude The exclusions.
|
||||
* @param array $roles The roles.
|
||||
* @return bool
|
||||
*/
|
||||
public static function show_data( $conditionals, $exclude, $roles ) {
|
||||
@ -250,7 +302,7 @@ class GeneratePress_Conditions {
|
||||
|
||||
// Show depending on location conditionals.
|
||||
if ( ! $show ) {
|
||||
foreach( ( array ) $conditionals as $conditional ) {
|
||||
foreach ( (array) $conditionals as $conditional ) {
|
||||
if ( in_array( 'general:site', $conditional ) ) {
|
||||
$show = true;
|
||||
} elseif ( is_singular() && in_array( 'general:singular', $conditional ) ) {
|
||||
@ -280,7 +332,7 @@ class GeneratePress_Conditions {
|
||||
|
||||
// Exclude based on exclusion conditionals.
|
||||
if ( $show ) {
|
||||
foreach( ( array ) $exclude as $conditional ) {
|
||||
foreach ( (array) $exclude as $conditional ) {
|
||||
if ( is_singular() && in_array( 'general:singular', $conditional ) ) {
|
||||
$show = false;
|
||||
} elseif ( is_archive() && in_array( 'general:archive', $conditional ) ) {
|
||||
@ -294,7 +346,7 @@ class GeneratePress_Conditions {
|
||||
}
|
||||
}
|
||||
} elseif ( is_singular() && strstr( $conditional['rule'], ':taxonomy:' ) ) {
|
||||
$tax = substr( $conditional['rule'], strrpos( $conditional['rule'], ':') + 1 );
|
||||
$tax = substr( $conditional['rule'], strrpos( $conditional['rule'], ':' ) + 1 );
|
||||
|
||||
if ( $tax && isset( $conditional['object'] ) && has_term( $conditional['object'], $tax ) ) {
|
||||
$show = false;
|
||||
@ -323,11 +375,11 @@ class GeneratePress_Conditions {
|
||||
* Returns the label for a saved location.
|
||||
*
|
||||
* @since 1.7
|
||||
* @param string $saved_location
|
||||
* @param string $saved_location The location.
|
||||
* @return string|bool
|
||||
*/
|
||||
static public function get_saved_label( $saved_location ) {
|
||||
$locations = self::get_conditions();
|
||||
public static function get_saved_label( $saved_location ) {
|
||||
$locations = self::get_conditions();
|
||||
|
||||
$rule = $saved_location['rule'];
|
||||
$object_id = $saved_location['object'];
|
||||
|
Reference in New Issue
Block a user