plugin_name = $plugin_name; $this->version = $version; require_once AMAZING_LINKER_PLUGIN_DIR . 'admin/includes/class-amazing-linker-callbackmanager.php'; $this->callbacks_mngr = new Amazing_Linker_Manager_Callbacks(); require_once AMAZING_LINKER_PLUGIN_DIR . 'admin/includes/class-amazing-linker-settingapi.php'; $this->settings = new Amazing_Linker_Settings_Api(); require_once AMAZING_LINKER_PLUGIN_DIR . 'admin/includes/class-amazing-linker-api.php'; $this->api = new Amazing_Linker_Api(); $this->api->set_credentials(); require_once AMAZING_LINKER_PLUGIN_DIR . 'includes/class-amazing-linker-product-table.php'; $this->table = new Amazing_Linker_Product_Table(); require_once AMAZING_LINKER_PLUGIN_DIR . 'includes/class-amazing-linker-database-query.php'; $this->database_query = new Amazing_Linker_Database_Query(); require_once AMAZING_LINKER_PLUGIN_DIR . 'includes/class-amazing-linker-helper.php'; $this->helper = new Amazing_Linker_Helper(); require_once AMAZING_LINKER_PLUGIN_DIR . 'includes/class-amazing-linker-background-update.php'; $this->background_update = new Amazing_Linker_Background_Update(); require_once AMAZING_LINKER_PLUGIN_DIR . 'admin/includes/class-amazing-linker-product-widget.php'; $this->credentials = array ( 'access_key_id' => 'Access Key ID', 'secret_access_key' => 'Secret Access Key' ); $this->associate = array ( 'associate_country' => 'Country', 'tracking_id' => 'Tracking ID', 'onelink_ad_instance_id' => 'OneLink Ad Instance ID' ); $this->setting = array ( 'button_text' => 'Small Button Text', 'large_button_text' => 'Large Button Text', 'button_color' => 'Button Color', 'button_text_color' => 'Button Text Color', 'new_tab_open' => 'Open link in new tab', 'nofollow_attribute' => 'Link has nofollow attribute', 'update_info' => 'Update Information at bottom', 'show_review' => 'Showing review quantity', 'show_rating' => 'Showing star rating', 'update_product' => 'Update Product Info Every', 'custom_css' => 'Custom CSS' ); $this->set_settings(); $this->set_sections(); $this->set_fields(); } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Amazing_Linker_Loader as all of the hooks are defined * in that particular class. * * The Amazing_Linker_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/amazing-linker-admin.css', array(), $this->version, 'all' ); wp_enqueue_style( 'farbtastic' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Amazing_Linker_Loader as all of the hooks are defined * in that particular class. * * The Amazing_Linker_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script( 'farbtastic' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/amazing-linker-admin.js', array( 'farbtastic', 'jquery' ), $this->version, true ); $amazing_linker_nonce = wp_create_nonce('amazing_linker_nonce'); wp_localize_script($this->plugin_name, 'amazing_linker_ajax_obj', array( 'amazing_linker_ajax_url' => admin_url('admin-ajax.php'), 'nonce' => $amazing_linker_nonce, )); wp_enqueue_script($this->plugin_name); # code editor for custom css input field of settings tab wp_enqueue_code_editor( array( 'type' => 'text/css' ) ); } public function amazing_linker_menus_sections() { add_menu_page( __('Amazing Linker', 'amazing-linker'), __('Amazing Linker', 'amazing-linker'), 'manage_options', 'amazing-linker-settings', array($this, "amazing_linker_main_layout"), AMAZING_LINKER_PLUGIN_URL . 'admin/images/menu-icon.png', null ); add_submenu_page( 'amazing-linker-settings', // The slug for the parent menu page to which this sub menu belongs 'Settings', // The text that's rendered in the browser title bar 'Settings', // The text to be rendered in the menu 'manage_options', // The capability required to access this menu item 'amazing-linker-settings', // The slug by which this sub menu is identified array($this, "amazing_linker_main_layout") // The function used to display this options for this menu's page ); } public function amazing_linker_main_layout() { include_once AMAZING_LINKER_PLUGIN_DIR . '/admin/partials/amazing-linker-admin-layout.php'; } public function settings_link( $links ) { if ( array_key_exists( 'deactivate', $links ) ) { $links['deactivate'] = str_replace( 'Settings'; return $links; } public function set_sections() { $args = array( array( 'id' => 'amazing_linker_credential_tab_section', 'title' => __( 'Credential Details', 'amazing-linker' ), 'callback' => array( $this->callbacks_mngr, 'credential_tab_helper_text' ), 'page' => 'amazing_linker_credential_tab' ), array( 'id' => 'amazing_linker_associate_tab_section', 'title' => __( 'Amazon Associate Details', 'amazing-linker' ), 'callback' => array( $this->callbacks_mngr, 'associate_tab_helper_text' ), 'page' => 'amazing_linker_associate_tab' ), array( 'id' => 'amazing_linker_settings_tab_section', 'title' => __( 'Amazing Linker Settings', 'amazing-linker' ), 'page' => 'amazing_linker_settings_tab' ) ); $this->settings->amazing_linker_set_sections( $args ); } public function set_fields() { $args = array(); foreach ( $this->credentials as $key => $value ) { $args[] = array( 'id' => $key, 'title' => $value, 'callback' => array( $this->callbacks_mngr, 'amazing_linker_input_field' ), 'page' => 'amazing_linker_credential_tab', 'section' => 'amazing_linker_credential_tab_section', 'args' => array( 'option_name' => 'amazing_linker_credential_tab_option', 'label_for' => $key, 'placeholder' => $value ) ); } foreach ( $this->associate as $key => $value ) { if ($key == 'associate_country') { $callback = 'amazing_linker_county_select_field'; } elseif($key == 'tracking_id' || $key == 'onelink_ad_instance_id') { $callback = 'amazing_linker_input_field'; } $args[] = array( 'id' => $key, 'title' => $value, 'callback' => array( $this->callbacks_mngr, $callback ), 'page' => 'amazing_linker_associate_tab', 'section' => 'amazing_linker_associate_tab_section', 'args' => array( 'option_name' => 'amazing_linker_associate_tab_option', 'label_for' => $key, 'placeholder' => $value ) ); } foreach ( $this->setting as $key => $value ) { if ($key == 'button_text' || $key == 'large_button_text') { $callback = 'amazing_linker_input_field'; $class=''; } elseif($key == 'button_color' || $key == 'button_text_color') { $callback = 'amazing_linker_colorpicker_field'; $class=''; } elseif($key == 'show_review' || $key == 'show_rating' || $key == 'new_tab_open' || $key == 'nofollow_attribute' || $key == 'update_info') { $callback = 'amazing_linker_checkbox_field'; $class='ui-toggle'; } elseif($key == 'update_product') { $callback = 'amazing_linker_interval_select_field'; $class=''; } elseif($key == 'custom_css') { $callback = 'amazing_linker_textarea_field'; $class=''; } $args[] = array( 'id' => $key, 'title' => $value, 'callback' => array( $this->callbacks_mngr, $callback ), 'page' => 'amazing_linker_settings_tab', 'section' => 'amazing_linker_settings_tab_section', 'args' => array( 'option_name' => 'amazing_linker_settings_tab_option', 'label_for' => $key, 'placeholder' => $value, 'class' => $class ) ); } $this->settings->amazing_linker_set_fields( $args ); } public function set_settings() { $args = array(); foreach( $this->credentials as $key => $value ) { $args[] = array( 'option_group' => 'amazing_linker_credential_tab_section', 'option_name' => 'amazing_linker_credential_tab_option', 'callback' => array( $this->callbacks_mngr, 'input_field_sanitization' ) ); } foreach( $this->associate as $key => $value ) { if ($key == 'associate_country') { $sanitize_callback = 'select_field_sanitization'; } elseif($key == 'tracking_id' || $key == 'onelink_ad_instance_id') { $sanitize_callback = 'input_field_sanitization'; } $args[] = array( 'option_group' => 'amazing_linker_associate_tab_section', 'option_name' => 'amazing_linker_associate_tab_option', 'callback' => array( $this->callbacks_mngr, $sanitize_callback ) ); } foreach( $this->setting as $key => $value ) { if ($key == 'button_text' || $key == 'large_button_text' || $key == 'button_color' || $key == 'button_text_color') { $sanitize_callback = 'input_field_sanitization'; } elseif($key == 'show_review' || $key == 'show_rating' || $key == 'new_tab_open' || $key == 'nofollow_attribute' || $key == 'update_info' ) { $sanitize_callback = 'checkbox_field_sanitization'; } elseif($key == 'update_product') { $sanitize_callback = 'select_field_sanitization'; } elseif($key == 'custom_css') { $sanitize_callback = 'textarea_field_sanitization'; } $args[] = array( 'option_group' => 'amazing_linker_settings_tab_section', 'option_name' => 'amazing_linker_settings_tab_option', 'callback' => array( $this->callbacks_mngr, $sanitize_callback ) ); } $this->settings->amazing_linker_set_settings( $args ); } public function amazing_linker_database_save_shortcode_items($post_id) { $content = get_post($post_id); set_time_limit(0); if ( shortcode_exists( 'amlinker' ) && has_shortcode( $content->post_content, 'amlinker' ) ) { $shortcode_attributes = $this->helper->shortcode_get_all_attributes('amlinker', $content->post_content); $single_items = []; foreach($shortcode_attributes as $shortcode_attribute) { $shortcode_type = sanitize_text_field($shortcode_attribute['type']); if($shortcode_type != 'similar_items' && ($shortcode_type != 'bestseller_vertical' && $shortcode_type != 'bestseller_horizontal') && ($shortcode_type != 'newrelease_vertical' && $shortcode_type != 'newrelease_horizontal')) { $shortcode_sanitized_items = sanitize_text_field($shortcode_attribute['items']); $shortcode_items = array_map('trim', explode(",",$shortcode_sanitized_items)); foreach($shortcode_items as $shortcode_item) { array_push($single_items,$shortcode_item); } $single_items = array_values(array_unique($single_items,SORT_REGULAR)); $single_items_confirm = []; foreach($single_items as $single_item) { if(!$this->database_query->item_exists_database($single_item,"single")) { $single_items_confirm[] = $single_item; } } $single_items = $single_items_confirm; $item_count = count($single_items); if(isset($single_items) && count($single_items)>0) { $single_items = $this->api->item_lookup($single_items); } if($item_count == 1 ){ $temp_item = []; array_push($temp_item,$single_items); $single_items = $temp_item; } if(isset($single_items) && count($single_items)>0) { $this->database_query->insert_item_database($single_items); } } } } } public function register_amazing_linker_widget() { register_widget('Amazing_Linker_Product_Widget'); } public function amazing_linker_get_country_flag() { check_ajax_referer('amazing_linker_nonce'); $country = $_POST['country']; switch ($country) { case "com": $class = "flag flag-us"; break; case "co.uk": $class = "flag flag-gb"; break; case "ca": $class = "flag flag-ca"; break; case "es": $class = "flag flag-es"; break; case "fr": $class = "flag flag-fr"; break; case "it": $class = "flag flag-it"; break; case "de": $class = "flag flag-de"; break; case "com.mx": $class = "flag flag-mx"; break; case "cn": $class = "flag flag-cn"; break; case "co.jp": $class = "flag flag-jp"; break; case "com.br": $class = "flag flag-br"; break; case "in": $class = "flag flag-in"; break; default: break; } $data=array( "success"=>true, "class"=>$class, ); wp_send_json_success($data); } # increase auto update time for gutenberg editor public function amazing_linker_block_editor_settings( $editor_settings, $post ) { $editor_settings['autosaveInterval'] = 86400; //number of second [default value is 10] return $editor_settings; } public function amazing_linker_review_notice() { $options = get_option('amazing_linker_review_notice'); $activation_time = get_option('amazing-linker-activation-time'); $notice = '

We have worked relentlessly to develop the plugin and it would really appreciate us if you dropped a short review about the plugin. Your review means a lot to us and we are working to make the plugin more awesome. Thanks for using Amazing Linker.
'; $notice .= '