balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-notice-overrides.php (2494B)


      1 <?php // phpcs:ignore WordPress.Files.FileName
      2 
      3 /**
      4  * Notice overrides for Redux Pro block plugins.
      5  *
      6  * @since   4.0.0
      7  * @package Redux Framework
      8  */
      9 
     10 namespace ReduxTemplates;
     11 
     12 if ( ! defined( 'ABSPATH' ) ) {
     13 	exit; // Exit if accessed directly.
     14 }
     15 
     16 /**
     17  * Redux Templates Notice Overrides Class
     18  *
     19  * @since 4.1.19
     20  */
     21 class Notice_Overrides {
     22 
     23 	/**
     24 	 * ReduxTemplates Notice_Overrides.
     25 	 *
     26 	 * @since 4.1.19
     27 	 */
     28 	public function __construct() {
     29 		add_action( 'admin_notices', array( $this, 'filter_notices' ), 0 );
     30 	}
     31 
     32 	/**
     33 	 * Filter out any notices before they're displayed.
     34 	 *
     35 	 * @since 4.0.0
     36 	 */
     37 	public function filter_notices() {
     38 		if ( \Redux_Helpers::mokama() ) {
     39 			$this->remove_filters_for_anonymous_class( 'admin_notices', 'QUBELY_PRO\Updater', 'show_invalid_license_notice' );
     40 		}
     41 	}
     42 
     43 	/**
     44 	 * Allow to remove method for an hook when, it's a class method used and class don't have variable, but you know the class name.
     45 	 *
     46 	 * @since 1.6.0
     47 	 *
     48 	 * @param string $hook_name Hook/action name to remove.
     49 	 * @param string $class_name Class name. `Colors::class` for example.
     50 	 * @param string $method_name Class method name.
     51 	 * @param int    $priority Action priority.
     52 	 *
     53 	 * @return bool
     54 	 */
     55 	public static function remove_filters_for_anonymous_class( $hook_name = '', $class_name = '', $method_name = '', $priority = 10 ) {
     56 		global $wp_filter;
     57 
     58 		// Take only filters on right hook name and priority.
     59 		if ( ! isset( $wp_filter[ $hook_name ][ $priority ] ) || ! is_array( $wp_filter[ $hook_name ][ $priority ] ) ) {
     60 			return false;
     61 		}
     62 
     63 		// Loop on filters registered.
     64 		foreach ( $wp_filter[ $hook_name ][ $priority ] as $unique_id => $filter_array ) {
     65 			// Test if filter is an array ! (always for class/method).
     66 			// Test if object is a class, class and method is equal to param !
     67 			if ( isset( $filter_array['function'] ) && is_array( $filter_array['function'] ) && is_object( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) === $class_name && $filter_array['function'][1] === $method_name ) {
     68 				// Test for WordPress >= 4.7 WP_Hook class (https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/).
     69 				if ( $wp_filter[ $hook_name ] instanceof \WP_Hook ) {
     70 					unset( $wp_filter[ $hook_name ]->callbacks[ $priority ][ $unique_id ] );
     71 				} else {
     72 					unset( $wp_filter[ $hook_name ][ $priority ][ $unique_id ] );
     73 				}
     74 			}
     75 		}
     76 
     77 		return false;
     78 	}
     79 }