plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the admin area. */ public function apffw_enqueue_styles() { $current_bytes_page = isset( $_GET['page'] ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : false; if($current_bytes_page == "bytes-product-frontend-info" || $current_bytes_page == "bytes-product-frontend-setting" || $current_bytes_page == "bytes-product-list"){ wp_enqueue_style( $this->plugin_name.'_bootstrap.min.css', plugin_dir_url( __FILE__ ) . 'css/bootstrap.min.css', array(), $this->version, 'all' ); // load bootstrap css wp_enqueue_style( $this->plugin_name.'_custom.admin.css', plugin_dir_url( __FILE__ ) . 'css/custom-admin.css', array(), $this->version, 'all' ); // load custom css } } /** * Register the JavaScript for the admin area. */ public function apffw_enqueue_scripts() { $current_bytes_page = isset( $_GET['page'] ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : false; if($current_bytes_page == "bytes-product-frontend-info" || $current_bytes_page == "bytes-product-frontend-setting" || $current_bytes_page == "bytes-product-list"){ wp_enqueue_script( 'bytes-add-product-frontend-for-woocommerce-admin.js', plugin_dir_url( __FILE__ ) . 'js/bytes-add-product-frontend-for-woocommerce-admin.js', array( 'jquery' ), $this->version, false ); wp_localize_script( 'bytes-add-product-frontend-for-woocommerce-admin.js', 'save_admin_product', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'security' => wp_create_nonce( 'bytes-admin-security' ), )); wp_enqueue_script( $this->plugin_name.'_bootstrap.min.js', plugin_dir_url( __FILE__ ) . 'js/bootstrap.min.js', array('jquery'), $this->version, true ); // load bootstrap JS } } /* *** load plugin setting link *** */ public function apffw_settings_link_bytes_add_product_frontend_for_woocommerce($setting_links){ $setting_links[] = '' . __('Settings', 'bytes_product_frontend') . ''; return $setting_links; } /* *** load admin menu page *** */ public function apffw_custom_menu_page_bytes_add_product_frontend_for_woocommerce(){ //The icon in Base64 format $icon_base64 = 'PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iNDAiIHZpZXdCb3g9IjAgMCAzMiA0MCIgZmlsbD0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I1IDI1LjQzNzUgMzguMDYyNUMyNi45ODg1IDM4LjA2MjUgMjguMjUgMzYuODAxIDI4LjI1IDM1LjI1QzI4LjI1IDMzLjY5OTIgMjYuOTg4NSAzMi40Mzc1IDI1LjQzNzUgMzIuNDM3NUMyMy44ODY3IDMyLjQzNzUgMjIuNjI1IDMzLjY5OTIgMjIuNjI1IDM1LjI1WiIgZmlsbD0id2hpdGUiLz4KPC9zdmc+Cg=='; //The icon in the data URI scheme $icon_data_uri = 'data:image/svg+xml;base64,'.$icon_base64; add_menu_page('Add products Frontend', 'Add products Frontend', 'manage_options', 'bytes-product-frontend-info', array($this, 'apffw_info_bytes_add_product_frontend_for_woocommerce'), $icon_data_uri, 59 ); add_submenu_page('bytes-product-frontend-info', 'Product List', 'Product List', 'manage_options', 'bytes-product-list', array($this, 'apffw_bytes_product_list_for_woocommerce'), null); add_submenu_page('bytes-product-frontend-info', 'Settings', 'Settings', 'manage_options', 'bytes-product-frontend-setting', array($this, 'apffw_setting_bytes_add_product_frontend_for_woocommerce'), null); add_submenu_page('bytes-product-frontend-info', 'About plugin', 'About plugin', 'manage_options', 'bytes-product-frontend-info'); } public function apffw_info_bytes_add_product_frontend_for_woocommerce(){ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/plugin-info-bytes-add-product-frontend.php'; } public function apffw_setting_bytes_add_product_frontend_for_woocommerce(){ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/plugin-setting-bytes-add-product-frontend.php'; } public function apffw_bytes_product_list_for_woocommerce(){ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/plugin-bytes-product-list.php'; } /* * Ajax file include */ public function apffw_frontend_product_management_admin_ajax(){ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/inc/ajax.php'; } /* * Display option */ public function apffw_frontend_product_display_options(){ /* section name, display name, callback to print description of section, page to which section is attached */ add_settings_section("header_section", "", array($this, "apffw_display_header_options_content"), "plugin-options"); /* setting name, display name, callback to print form element, page in which field is displayed, section to which it belongs. last field section is optional */ add_settings_field("frontend_product_additional_fields", "Product Fields", array($this, "apffw_display_additional_field_bytes_product_frontend_form"), "plugin-options", "header_section"); add_settings_field("frontend_product_status", "Product Status", array($this, "apffw_display_product_status_field_bytes_product_frontend_form"), "plugin-options", "header_section"); add_settings_field("frontend_product_category", "Select Product Categories", array($this, "apffw_display_product_category_field_bytes_product_frontend_form"), "plugin-options", "header_section"); add_settings_field("frontend_product_user_role", "Select user role which can create or edit product", array($this, "apffw_display_user_role_field_bytes_product_frontend_form"), "plugin-options", "header_section"); add_settings_field("frontend_product_save_update_email", "Email notification for user", array($this, "apffw_display_send_email_notification_create_update_product"), "plugin-options", "header_section"); add_settings_field("frontend_product_save_update_email_admin", "Email notification for administrator", array($this, "apffw_display_send_email_notification_create_update_product_admin"), "plugin-options", "header_section"); /* section name, form element name, callback for sanitization */ register_setting("header_section", "frontend_product_additional_fields", array( 'sanitize_callback' => array( $this, 'apffw_sanitize_array_setting' ) )); register_setting("header_section", "frontend_product_status"); register_setting("header_section", "frontend_product_category", array( 'sanitize_callback' => array( $this, 'apffw_sanitize_array_setting' ) )); register_setting("header_section", "frontend_product_user_role", array( 'sanitize_callback' => array( $this, 'apffw_sanitize_array_setting' ) )); register_setting("header_section", "frontend_product_save_update_email"); register_setting("header_section", "frontend_product_save_update_email_admin"); } /** * These settings are all rendered as groups of checkboxes (categories, fields, * roles), so the stored value must always be an array. Without this, submitting * the form with every checkbox unchecked stores a non-array value (WordPress's * Settings API saves `null`/'' when a checkbox-array field is entirely absent * from $_POST), which then fatals on the next page load wherever the option is * read with in_array(). */ public function apffw_sanitize_array_setting( $value ){ if ( ! is_array( $value ) ) { return array(); } return array_map( 'sanitize_text_field', wp_unslash( $value ) ); } /* *** add author support in admin *** */ public function apffw_add_author_support(){ add_post_type_support('product', 'author'); } /* *** set permalink *** */ public function apffw_set_permalink_structure(){ if(get_option('bytes_permalink_update') == '1'){ global $wp_rewrite; $wp_rewrite->set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules(); update_option('bytes_permalink_update', '2'); } } public function apffw_display_header_options_content(){ echo "

Fields Options

"; echo '
'; } public function apffw_display_additional_field_bytes_product_frontend_form(){ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/setting/plugin-setting-additional-fields.php'; } public function apffw_display_product_status_field_bytes_product_frontend_form(){ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/setting/plugin-setting-product-status.php'; } public function apffw_display_product_category_field_bytes_product_frontend_form(){ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/setting/plugin-setting-product-category.php'; } public function apffw_display_user_role_field_bytes_product_frontend_form(){ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/setting/plugin-setting-user-role.php'; } public function apffw_display_send_email_notification_create_update_product(){ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/setting/plugin-setting-email.php'; } public function apffw_display_send_email_notification_create_update_product_admin(){ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/setting/plugin-setting-email-admin.php'; echo '
'; } /* *** add columns to Product List *** */ public function apffw_add_product_columns($columns){ return array_merge($columns, array( 'product_status' => __('Product Status', 'bytes_product_frontend'), )); } /* *** add checkbox to Post List *** */ function apffw_add_custom_product_columns($column, $post_id){ switch($column){ case 'product_status': $product_status = get_post_meta($post_id, 'product_status', true); $msg = ($product_status == 1) ? "Frontend product" : "-"; esc_html_e($msg, 'bytes_product_frontend'); break; } } } }