eturn $filter ? $filter['is_action'] : true; } public function get_priority() { $priority = $this->get_option( $this->get_default_priority(), 'priority' ); /** * Filter to adjust priority for a certain shopmark e.g. the unit price on single product page. * * The dynamic portion of the hook name, `$this->get_hook_prefix()` constructs an individual * hook name containing location and type of the shopmark. * * Example hook name: `woocommerce_gzd_shopmark_single_product_unit_price_priority` * * @param integer $priority The priority for the current shopmark. * @param Shopmark $shopmark The shopmark object. * * @since 3.0.0 * */ return apply_filters( $this->get_hook_prefix() . 'priority', $priority, $this ); } public function get_filter() { $filter = $this->get_option( $this->get_default_filter(), 'filter' ); /** * Filter to adjust the hook name for a certain shopmark e.g. the unit price on single product page. * * The hook name returned should be a valid WooCommerce hook which might be executed within the chosen location * e.g. on the single product page. * The dynamic portion of the hook name, `$this->get_hook_prefix()` constructs an individual * hook name containing location and type of the shopmark. * * Example hook name: `woocommerce_gzd_shopmark_single_product_unit_price_filter` * * @param integer $filter The hook name for the current shopmark. * @param Shopmark $shopmark The shopmark object. * * @since 3.0.0 * */ $filtered = apply_filters( $this->get_hook_prefix() . 'filter', $filter, $this ); $has_filtered = $filter !== $filtered; $filter = $filtered; // In case the filter was not adjusted by a third party, make sure the filter does really exist to prevent errors. if ( ! $has_filtered && ( 'woocommerce_' === substr( $filter, 0, 12 ) || ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) ) { if ( ! Shopmarks::get_filter( $this->get_location(), $filter ) ) { $filter = $this->get_default_filter(); } } return $filter; } public function is_default_enabled() { return $this->default_enabled; } public function is_enabled() { $is_enabled = $this->get_option( $this->is_default_enabled() ? 'yes' : 'no' ); return 'yes' === $is_enabled; } public function execute() { if ( is_null( $this->get_callback() ) ) { return; } if ( ! $this->is_enabled() ) { return; } if ( $this->get_is_action() ) { add_action( $this->get_filter(), $this->get_callback(), $this->get_priority(), $this->get_number_of_params() ); } else { add_filter( $this->get_filter(), $this->get_callback(), $this->get_priority(), $this->get_number_of_params() ); } } public function remove() { if ( is_null( $this->get_callback() ) ) { return; } if ( ! $this->is_enabled() ) { return; } if ( $this->get_is_action() ) { remove_action( $this->get_filter(), $this->get_callback(), $this->get_priority() ); } else { remove_filter( $this->get_filter(), $this->get_callback(), $this->get_priority() ); } } }