Astra_Ext_Advanced_Hooks_Meta::hook_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: addons/advanced-hooks/classes/class-astra-ext-advanced-hooks-meta.php
		public static function hook_same_display_on_notice( $post_type, $option ) {
			global $wpdb;
			global $post;
			$all_rules        = array();
			$already_set_rule = array();
			$layout   = isset( $option['layout'] ) ? $option['layout'] : '';
			$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 ) {
				$layout_data = get_post_meta( $header->ID, $layout, true );
				if ( 'hooks' === $layout_data ) {
					continue;
				};
				$location_rules = unserialize( $header->meta_value ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
				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,
									'layout' => $layout_data,
								);
							}
						} else {
							$all_rules[ $rule ][ $header->ID ] = array(
								'ID'     => $header->ID,
								'name'   => $header->post_title,
								'layout' => $layout_data,
							);
						}
					}
				}
			}
			if ( empty( $post ) ) {
				return;
			}
			$current_post_data   = get_post_meta( $post->ID, $location, true );
			$current_post_layout = get_post_meta( $post->ID, $layout, 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;
								}
								if ( '0' !== $data['layout'] && $current_post_layout === $data['layout'] ) {
									$already_set_rule[] = $data['name'];
								}
							}
						}
					} else {
						foreach ( $all_rules[ $c_rule ] as $p_id => $data ) {
							if ( $p_id == $post->ID ) {
								continue;
							}
							if ( '0' !== $data['layout'] && $current_post_layout === $data['layout'] ) {
								$already_set_rule[] = $data['name'];
							}
						}
					}
				}
			}
			if ( ! empty( $already_set_rule ) ) {
				add_action(
					'admin_notices',
					function() use ( $already_set_rule, $current_post_layout ) {
						$rule_set_titles = '<strong>' . implode( ',', $already_set_rule ) . '</strong>';
						$layout          = '<strong>' . ucfirst( $current_post_layout ) . '</strong>';
						/* translators: %s layout. */
						$notice = sprintf( __( 'Another %s Layout is selected for the same display rules.', 'astra-addon' ), $layout );
						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. |