Astra_Target_Rules_Fields::same_display_on_notice( int $post_type, array $option )
Same display_on notice.
Description
Parameters
- $post_type
-
(int) (Required) Post Type.
- $option
-
(array) (Required) meta option name.
Source
File: classes/modules/target-rule/class-astra-target-rules-fields.php
public static function same_display_on_notice( $post_type, $option ) {
global $wpdb;
global $post;
$all_rules = array();
$already_set_rule = array();
$location = isset( $option['location'] ) ? $option['location'] : '';
$all_headers = $wpdb->get_results(
$wpdb->prepare(
"SELECT p.ID, p.post_title, pm.meta_value FROM {$wpdb->postmeta} as pm
INNER JOIN {$wpdb->posts} as p ON pm.post_id = p.ID
WHERE pm.meta_key = %s
AND p.post_type = %s
AND p.post_status = 'publish'",
$location,
$post_type
)
);
foreach ( $all_headers as $header ) {
$location_rules = maybe_unserialize( $header->meta_value );
if ( is_array( $location_rules ) && isset( $location_rules['rule'] ) ) {
foreach ( $location_rules['rule'] as $key => $rule ) {
if ( ! isset( $all_rules[ $rule ] ) ) {
$all_rules[ $rule ] = array();
}
if ( 'specifics' == $rule && isset( $location_rules['specific'] ) && is_array( $location_rules['specific'] ) ) {
foreach ( $location_rules['specific'] as $s_index => $s_value ) {
$all_rules[ $rule ][ $s_value ][ $header->ID ] = array(
'ID' => $header->ID,
'name' => $header->post_title,
);
}
} else {
$all_rules[ $rule ][ $header->ID ] = array(
'ID' => $header->ID,
'name' => $header->post_title,
);
}
}
}
}
if ( empty( $post ) ) {
return;
}
$current_post_data = get_post_meta( $post->ID, $location, true );
if ( is_array( $current_post_data ) && isset( $current_post_data['rule'] ) ) {
foreach ( $current_post_data['rule'] as $c_key => $c_rule ) {
if ( ! isset( $all_rules[ $c_rule ] ) ) {
continue;
}
if ( 'specifics' === $c_rule ) {
foreach ( $current_post_data['specific'] as $s_index => $s_id ) {
if ( ! isset( $all_rules[ $c_rule ][ $s_id ] ) ) {
continue;
}
foreach ( $all_rules[ $c_rule ][ $s_id ] as $p_id => $data ) {
if ( $p_id == $post->ID ) {
continue;
}
$already_set_rule[] = $data['name'];
}
}
} else {
foreach ( $all_rules[ $c_rule ] as $p_id => $data ) {
if ( $p_id == $post->ID ) {
continue;
}
$already_set_rule[] = $data['name'];
}
}
}
}
if ( ! empty( $already_set_rule ) ) {
add_action(
'admin_notices',
function() use ( $already_set_rule ) {
$rule_set_titles = '<strong>' . implode( ',', $already_set_rule ) . '</strong>';
/* translators: %s post title. */
$notice = sprintf( __( 'The same display setting is already exist in %s post/s.', 'astra-addon' ), $rule_set_titles );
echo '<div class="error">';
echo '<p>' . $notice . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '</div>';
}
);
}
}
Expand full source code Collapse full source code View on Trac
Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |