*/ class Affreviews { /** * The loader that's responsible for maintaining and registering all hooks that power * the plugin. * * @since 1.0.0 * @access protected * @var Affreviews_Loader $loader Maintains and registers all hooks for the plugin. */ protected $loader; /** * The unique identifier of this plugin. * * @since 1.0.0 * @access protected * @var string $plugin_name The string used to uniquely identify this plugin. */ protected $plugin_name; /** * The current version of the plugin. * * @since 1.0.0 * @access protected * @var string $version The current version of the plugin. */ protected $version; /** * Define the core functionality of the plugin. * * Set the plugin name and the plugin version that can be used throughout the plugin. * Load the dependencies, define the locale, and set the hooks for the admin area and * the public-facing side of the site. * * @since 1.0.0 */ public function __construct() { if ( defined( 'AFFREVIEWS_VERSION' ) ) { $this->version = AFFREVIEWS_VERSION; } else { $this->version = '1.0.0'; } $this->plugin_name = 'affreviews'; $this->load_dependencies(); $this->define_admin_hooks(); $this->define_public_hooks(); $this->define_link_hooks(); } /** * Load the required dependencies for this plugin. * * Include the following files that make up the plugin: * * - Affreviews_Loader. Orchestrates the hooks of the plugin. * - Affreviews_Admin. Defines all hooks for the admin area. * - Affreviews_Public. Defines all hooks for the public side of the site. * * Create an instance of the loader which will be used to register the hooks * with WordPress. * * @since 1.0.0 * @access private */ private function load_dependencies() { /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-affreviews-loader.php'; /** * The class responsible for defining all actions that occur in the admin area. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-affreviews-admin.php'; /** * The class responsible for defining all actions that occur in the public-facing * side of the site. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-affreviews-public.php'; /** * The class responsible for blocks. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'blocks/class-affreviews-blocks.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'blocks/class-affreviews-sample-review.php'; /** * Plugin helpers. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/affreviews-helpers.php'; /** * Link cloaking (/go/ links). */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-affreviews-links.php'; /** * Demo reviews. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-affreviews-demo.php'; /** * Init classes */ $this->loader = new Affreviews_Loader(); } /** * Register all of the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { // Admin $plugin_admin = new Affreviews_Admin( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_action( 'init', $plugin_admin, 'register_cpt' ); $this->loader->add_action( 'cmb2_admin_init', $plugin_admin, 'register_metaboxes' ); $this->loader->add_action( 'init', $plugin_admin, 'register_review_meta' ); $this->loader->add_action( 'rest_after_insert_' . AFFREVIEWS_CPT, $plugin_admin, 'delete_empty_review_meta', 10, 2 ); $this->loader->add_filter( 'rest_prepare_' . AFFREVIEWS_CPT, $plugin_admin, 'hide_rest_affiliate_link', 10, 2 ); $this->loader->add_filter( 'rest_request_before_callbacks', $plugin_admin, 'restrict_hidden_reviews_rest', 10, 3 ); $this->loader->add_action( 'add_meta_boxes_' . AFFREVIEWS_CPT, $plugin_admin, 'remove_custom_fields_box' ); $this->loader->add_action( 'enqueue_block_editor_assets', $plugin_admin, 'enqueue_review_details_panel' ); $this->loader->add_action( 'admin_menu', $plugin_admin, 'options_page' ); $this->loader->add_action( 'init', $plugin_admin, 'create_thumb_sizes' ); $this->loader->add_action( 'admin_init', $plugin_admin, 'register_settings' ); $this->loader->add_action( 'rest_api_init', $plugin_admin, 'register_settings' ); $this->loader->add_action( 'rest_api_init', $plugin_admin, 'register_guide_routes' ); // Demo reviews $plugin_demo = new Affreviews_Demo(); $this->loader->add_action( 'rest_api_init', $plugin_demo, 'register_routes' ); $this->loader->add_action( 'admin_notices', $plugin_demo, 'admin_notice' ); $this->loader->add_action( 'admin_post_affreviews_import_demo', $plugin_demo, 'handle_import' ); $this->loader->add_action( 'admin_post_affreviews_dismiss_demo', $plugin_demo, 'handle_dismiss' ); // Blocks $plugin_blocks = new Affreviews_Blocks( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'init', $plugin_blocks, 'register_blocks' ); $this->loader->add_action( 'enqueue_block_assets', $plugin_blocks, 'register_editor_styles' ); $this->loader->add_action( 'enqueue_block_assets', $plugin_blocks, 'register_editor_preview_styles' ); $this->loader->add_action( 'enqueue_block_editor_assets', $plugin_admin, 'enqueue_editor_scripts' ); $this->loader->add_action( 'init', $plugin_blocks, 'register_pattern_categories' ); $this->loader->add_action( 'init', $plugin_blocks, 'register_patterns' ); $this->loader->add_action( 'rest_api_init', $plugin_blocks, 'register_rest_query_args' ); // Filters $this->loader->add_filter( 'safe_style_css', $plugin_admin, 'kses_extend_css_filters' ); $this->loader->add_filter( 'block_categories_all', $plugin_blocks, 'register_block_categories' ); $this->loader->add_filter( 'query_loop_block_query_vars', $plugin_blocks, 'filter_query_reviews_post_type', 10, 2 ); $this->loader->add_filter( 'query_loop_block_query_vars', $plugin_blocks, 'filter_query_review_categories', 10, 2 ); $this->loader->add_filter( 'pre_render_block', $plugin_blocks, 'setup_review_context_post', PHP_INT_MAX, 2 ); $this->loader->add_filter( 'render_block_affreviews/review-context', $plugin_blocks, 'reset_review_context_post', 10, 1 ); $this->loader->add_filter( 'query_loop_block_query_vars', $plugin_blocks, 'filter_query_rating_orderby', 10, 2 ); $this->loader->add_filter( 'query_loop_block_query_vars', $plugin_blocks, 'filter_query_selected_reviews', 10, 2 ); } /** * Register all of the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_public_hooks() { $plugin_public = new Affreviews_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_filter( 'render_block', $plugin_public, 'enqueue_layouts_on_render', 10, 2 ); // $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); // Disable it for now because there are no js at the moment $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_css_vars' ); } /** * Register the link cloaking hooks. Each one does nothing while cloaking * is off in the General settings. * * @since 2.0.0 * @access private */ private function define_link_hooks() { $plugin_links = new Affreviews_Links(); $this->loader->add_action( 'init', $plugin_links, 'add_rewrite_rule' ); $this->loader->add_filter( 'query_vars', $plugin_links, 'add_query_var' ); $this->loader->add_action( 'parse_request', $plugin_links, 'handle_request' ); $this->loader->add_action( 'update_option_affreviews_general_settings', $plugin_links, 'settings_updated', 10, 2 ); $this->loader->add_action( 'add_option_affreviews_general_settings', $plugin_links, 'settings_added', 10, 2 ); // After delete_empty_review_meta (10), so a cleared slug is not checked. $this->loader->add_action( 'rest_after_insert_' . AFFREVIEWS_CPT, $plugin_links, 'dedupe_saved_slug', 20 ); $this->loader->add_action( 'added_post_meta', $plugin_links, 'dedupe_slug_meta', 10, 4 ); $this->loader->add_action( 'updated_post_meta', $plugin_links, 'dedupe_slug_meta', 10, 4 ); $this->loader->add_action( 'before_delete_post', $plugin_links, 'delete_clicks' ); $this->loader->add_filter( 'manage_' . AFFREVIEWS_CPT . '_posts_columns', $plugin_links, 'add_list_column' ); $this->loader->add_action( 'manage_' . AFFREVIEWS_CPT . '_posts_custom_column', $plugin_links, 'render_list_column', 10, 2 ); } /** * Run the loader to execute all of the hooks with WordPress. * * @since 1.0.0 */ public function run() { $this->loader->run(); } /** * The name of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. * * @since 1.0.0 * @return string The name of the plugin. */ public function get_plugin_name() { return $this->plugin_name; } /** * The reference to the class that orchestrates the hooks with the plugin. * * @since 1.0.0 * @return Affreviews_Loader Orchestrates the hooks of the plugin. */ public function get_loader() { return $this->loader; } /** * Retrieve the version number of the plugin. * * @since 1.0.0 * @return string The version number of the plugin. */ public function get_version() { return $this->version; } }