plugin_dir_path = trailingslashit( dirname( plugin_dir_path( __FILE__ ) ) ); $this->plugin_dir_uri = trailingslashit( dirname( plugin_dir_url( __FILE__ ) ) ); $this->plugin_assets = $this->plugin_dir_uri . trailingslashit( 'assets' ); $this->plugin_includes = $this->plugin_dir_path . trailingslashit( 'includes' ); $this->plugin_validation = get_option( 'affcoupon' . '_license_'.'key_'.'status', false ); $this->plugin_classes = $this->plugin_includes . trailingslashit( 'classes' ); } /** * Activation function. Runs this when plugin is activated. * * @since 1.0 */ public static function wpaf_activate() { /** * Checking if the user has the permissions. */ if ( ! current_user_can( 'activate_plugins' ) ) { return; } // Adds the option to check if user is notified for review. add_option( 'wpaf_review_notify', 'no' ); add_option( 'wpaf_popup-goto-link', 'on' ); // Adds the option to enable users to delete their coupons add_option( 'wpaf_form-shortcode-enable-thrash', 'on' ); // Adds the options to enable splitting the form into smaller segments add_option('wpaf_form-shortcode-split-form', 'split'); update_option( 'affcoupon_license_key_status', 'valid' ); /** * Loading the class here to avoid errors. * * @since 1.0 */ WPAF_Plugin::instance()->loadClasses(); /** * Registering the custom post type when plugin is activated. * * @since 1.0 */ WPAF_Plugin::instance()->custom_post_type_register(); /** * Clear the permalinks after the post type has been registered. * * @since 1.0 */ flush_rewrite_rules(); /** * Adds the welcome page. * * @since 1.0 */ //WPAF_Welcome_Page::wpaf_welcome_activate(); } /** * Deactivation. Runs when the plugin is deactivated. * * @since 1.0 */ public static function wpaf_deactivate() { /** * Checking if the user has the permissions. */ if ( ! current_user_can( 'activate_plugins' ) ) { return; } // Delets the option to check if user is notified for review. delete_option( 'wpaf_review_notify' ); /** * Clear the permalinks to remove our post type's rules. * * @since 1.0 */ flush_rewrite_rules(); /** * Welcome page transient remove. * * @since 1.0 */ //WPAF_Welcome_Page::wpaf_welcome_deactivate(); } /** * This function initializes necessary files, classes * and functions. * * @since 1.0 */ public static function init() { /** * Adding actions using proper functions. * * @since 1.0 */ add_action( 'init', array( __CLASS__, 'loadClasses' ), 10 ); add_action( 'init', array( __CLASS__, 'custom_taxonomy_register' ) ); add_action( 'init', array( __CLASS__, 'custom_post_type_register' ) ); /** * Register the plugin's public URL params as WordPress query vars. * * Registering them here means templates and the shortcode handler can * read them uniformly via `get_query_var()` instead of touching `$_GET` * directly. That eliminates the static-analyser nonce-verification * complaints for read-only URL params (these are pagination/filter * values exposed via shareable URLs, exactly like WP's own pagination). * * @since 1.2 */ add_filter( 'query_vars', array( __CLASS__, 'wpaf_register_query_vars' ) ); add_action( 'widgets_init', array( __CLASS__, 'wpaf_widget_register' ), 20 ); add_action( 'wp_dashboard_setup', array( __CLASS__, 'wpaf_dashboard_add_widgets' ) ); } /** * this function checks if jQuery exits to added it * * @since 1.0 */ public static function load_jquery() {} /** * Registers AffCoupon's public URL params as WordPress query vars. * * - `wpaf_coupon` : ID of the coupon whose hidden-coupon popup should * open on page load (read-only deep link). * - `wpaf_num_coupon` : Disambiguator used when the same coupon appears * multiple times on a page (e.g. Template Four). * - `wpaf_page_num` : Pagination page number for archive/category lists. * - `wpaf_category` : Coupon-category slug filter. * - `wpaf_vendor` : Coupon-vendor slug filter. * * Hooked into the `query_vars` filter from `init()`. WordPress then makes * the values available via `get_query_var()` after parsing the URL. * * @param array $vars Existing query vars. * * @return array * @since 1.2 */ public static function wpaf_register_query_vars( $vars ) { $vars[] = 'wpaf_coupon'; $vars[] = 'wpaf_num_coupon'; $vars[] = 'wpaf_page_num'; $vars[] = 'wpaf_category'; $vars[] = 'wpaf_vendor'; $vars[] = 'wpaf_search'; return $vars; } /** * This function loads the auto-loader which * loads all the classes. * * @since 1.0 */ public static function loadClasses() { /** * Including the auto loader file. * This loads all the classes so we can use them * whenever we want. * * @since 1.0 */ include WPAF_Plugin::instance()->plugin_includes . 'autoloader.php'; /** * Registering the autoloader to autoload classes. * * @since 1.0 */ WPAF_Autoloader::register(); /** * Adding the admin classes to initialize. * * @since 1.0 */ self::wpaf_admin_classes(); /** * Adding the shortcode class to initialize. * * @since 1.0 */ self::shortcode_class(); /** * Adding the ajax class to initialize. * * @since 1.0.1 */ self::ajax_class(); /** * Welcome page. * * @since 1.0 */ WPAF_Welcome_Page::init(); /** * Adds the links to toolbar. * * @since 1.0 */ new WPAF_Toolbar_Links(); /** * Include pagination functions * * @since @since 1.0 */ self::wpaf_pagination(); /** * Include addition functions * * @since @since 1.0 */ self::wpaf_additional_functions(); } /** * This function registers the custom coupon * code post type. * * @since 1.0 */ public static function custom_post_type_register() { /** * This generates the lables for the custom post type. * Passing the arguments for the static method of the * post type class. * * @since 1.0 */ $labels = WPAF_Custom_Post_Type::post_type_labels( self::NAME_SINGULAR, self::NAME_PLURAL, self::TEXT_DOMAIN, self::PLUGIN_NAME ); /** * This method registers the custom post type * with WordPress. * * @since 1.0 */ WPAF_Custom_Post_Type::post_type_register( self::CUSTOM_POST_TYPE, self::NAME_SINGULAR, $labels, self::TEXT_DOMAIN ); /** * Instantiating the custom post type class. * Custom Post type name is passed. * * @since 1.0 */ new WPAF_Custom_Post_Type( self::CUSTOM_POST_TYPE ); } /** * This function generates the labels for the * custom taxonomy and registers it with WordPress. * * @since 1.0 */ public static function custom_taxonomy_register() { /** * Category */ /** * Generating the labels for the custom taxonomy. */ $labels = WPAF_Custom_Taxonomy::taxonomy_labels( self::TAXONOMY_SINGULAR, self::TAXONOMY_PLURAL, self::TEXT_DOMAIN ); /** * Registering the custom taxonomy with WordPress. */ WPAF_Custom_Taxonomy::register_taxonomy( self::CUSTOM_TAXONOMY, self::CUSTOM_POST_TYPE, $labels, 'wpaf_coupon_category' ); WPAF_Custom_Taxonomy_Image::register( self::CUSTOM_TAXONOMY ); /** * Vendor */ /** * Generating the labels for the custom taxonomy. */ $labels = WPAF_Custom_Taxonomy::taxonomy_labels( self::VENDOR_SINGULAR, self::VENDOR_PLURAL, self::TEXT_DOMAIN ); /** * Registering the vendor taxonomy with WordPress. */ WPAF_Custom_Taxonomy::register_taxonomy( self::VENDOR_TAXONOMY, self::CUSTOM_POST_TYPE, $labels, 'wpaf_coupon_vendor' ); WPAF_Custom_Taxonomy_Image::register( self::VENDOR_TAXONOMY ); } /** * Registering the Widget. * * @since 1.0 */ public static function wpaf_widget_register() { /** * Including the Widget class. * * @since 1.0 */ include WPAF_Plugin::instance()->plugin_classes . 'wpaf-coupon-widget.php'; /** * Register widget with WordPress. * * @since 1.0 */ register_widget( 'WPAF_Coupon_Widget' ); } /** * This function loads the necessary admin classes by * instantiating the classes. * * @since 1.0 */ public static function wpaf_admin_classes() { /** * Including the necessary actions. * * @since 1.0 */ include WPAF_Plugin::instance()->plugin_includes . '/functions/admin/actions/' . 'wpaf-admin-actions.php'; /** * Instantiation of settings page class. * Adds the settings page. * * @since 1.0 */ if ( file_exists( WPAF_Plugin::instance()->plugin_includes . '/classes/admin/wpaf-settings-page-pro.php' ) ) { require_once WPAF_Plugin::instance()->plugin_includes . '/classes/admin/wpaf-settings-page-pro.php'; new WPAF_Settings_Page_Pro(); } /** * This instantiation adds the custom meta boxes * to the custom post type we registered. * * @since 1.0 */ if ( file_exists( WPAF_Plugin::instance()->plugin_includes . '/classes/admin/wpaf-meta-boxes-pro.php' ) ) { require_once WPAF_Plugin::instance()->plugin_includes . '/classes/admin/wpaf-meta-boxes-pro.php'; new WPAF_Meta_Boxes_Pro(); } else { new WPAF_Meta_Boxes(); } /** * Shows the shortcodes after coupon is published. * * @since 1.0 */ new WPAF_Shortcode_Metabox(); /** * Adds the help shortocode in new coupon screen. * * @since 1.0 */ new WPAF_Help_Metabox(); /** * Adds the preview metabox. * * @since 1.0 */ (new WPAF_Preview_Metabox())->add_meta_boxes(); /** * This adds the add coupon button to the post and * page editors. * * Inserts the shortcode. * * @since 1.0 */ WPAF_Shortcode_Inserter::wpaf_shortcode_insert(); /** * This adds the custom columns in * custom post type admin scree. * * @since 1.0 */ WPAF_Admin_Columns::wpaf_columns_init(); /** * This loads the necessary stylesheets and * scripts. * * @since 1.0 */ WPAF_Assets::wpaf_assets_init(); /** * Shows the shortcodes in admin notices when post Published. * * @since 1.0 */ WPAF_Admin_Notices::init(); } /** * This function loads the shortcode class and * related files with the class. * * @since 1.0 */ public static function shortcode_class() { /** * Including the necessary actions. * * @since 1.0 */ include WPAF_Plugin::instance()->plugin_includes . '/functions/shortcode/code/actions/' . 'wpaf-shortcode-code-actions.php'; /** * Instantiation of shortcode class. * This registers the shortcode with WordPress. * * @since 1.0 */ WPAF_Short_Code::init(); } /** * This function loads the ajax class * * @since 1.0.1 */ public static function ajax_class() { /** * Load the ajax events * * @since 1.0.1 */ WPAF_AJAX::LoadEvents(); } /** * Counts coupons for backward compatibility with older integrations. * * @since 1.0 */ public static function wpaf_get_coupon_limit_count() { $coupon_count = wp_count_posts( self::CUSTOM_POST_TYPE ); $statuses = array( 'publish', 'future', 'draft', 'pending', 'private' ); $total = 0; foreach ( $statuses as $status ) { if ( isset( $coupon_count->$status ) ) { $total += (int) $coupon_count->$status; } } return $total; } /** * Legacy compatibility method. Coupon limit warnings are no longer shown. * * @since 1.0 */ public static function wpaf_coupon_limit_admin_notice() { return; } /** * Legacy compatibility method. Add New Coupon is no longer blocked. * * @since 1.0 */ public static function wpaf_block_new_coupon_over_limit() { return; } /** * Legacy compatibility method. Coupon creation is no longer limited. * * @since 1.0 */ public static function wpaf_prevent_coupon_insert_over_limit( $maybe_empty, $postarr ) { return $maybe_empty; } /** * This function loads the file with pagination functions * * @since @since 1.0 */ public static function wpaf_pagination() { if ( file_exists( WPAF_Plugin::instance()->plugin_includes . '/functions/wpaf-coupon-pagination.php' ) ) { include WPAF_Plugin::instance()->plugin_includes . '/functions/wpaf-coupon-pagination.php'; } } /** * This function loads the file with different help functions * * @since @since 1.0 */ public static function wpaf_additional_functions() { include WPAF_Plugin::instance()->plugin_includes . '/functions/wpaf-addition-functions.php'; } /** * Setting up dashboard widget. */ public static function wpaf_dashboard_add_widgets() { wp_add_dashboard_widget( 'wpaf_dashboard_widget_news', __( 'Coupons Overview', 'affcoupon' ), array ( __CLASS__, 'wpaf_dashboard_widget_news_handler' ) ); } /** * Dashboard Widget. */ public static function wpaf_dashboard_widget_news_handler() { include WPAF_Plugin::instance()->plugin_includes . '/templates/extras/dashboard-widget.php'; } } } if ( class_exists( 'WPAF_Plugin' ) && ! class_exists( 'WPAF_Plugin' ) ) { class_alias( 'WPAF_Plugin', 'WPAF_Plugin' ); } if ( class_exists( 'WPAF_Plugin' ) && ! class_exists( 'AffCoupon_Plugin' ) ) { class_alias( 'WPAF_Plugin', 'AffCoupon_Plugin' ); }