options = affpromos_get_options(); // Initialize add_action('admin_menu', array( &$this, 'add_admin_menu') ); add_action('admin_init', array( &$this, 'init_settings') ); add_action('admin_init', 'do_admin_action' ); } function add_admin_menu() { /* * Source: https://codex.wordpress.org/Function_Reference/add_options_page */ add_submenu_page( 'edit.php?post_type=affpromos_promotion', __( 'Affiliate Promotions - Settings', AFFILIATE_PROMOTIONS_PLUG ), // Page title __( 'Settings', AFFILIATE_PROMOTIONS_PLUG ), // Menu title 'manage_options', // Capabilities 'affpromos_settings', // Menu slug array( &$this, 'options_page' ) // Callback ); } function init_settings() { register_setting( 'affpromos_settings', 'affpromos_settings', array( &$this, 'validate_input_callback' ) ); // SECTION: Quickstart // add_settings_section( // 'affpromos_settings_section_quickstart', // __('Quickstart Guide', AFFILIATE_PROMOTIONS_PLUG), // array( &$this, 'section_quickstart_render' ), // 'affpromos_settings' // ); // SECTION TWO add_settings_section( 'affpromos_settings_section_promotions', __('Sync data settings', AFFILIATE_PROMOTIONS_PLUG), null, 'affpromos_settings' ); add_settings_field( 'affpromos_settings_promotion_aff_token', __('AccessTrade Access Token', AFFILIATE_PROMOTIONS_PLUG), array(&$this, 'promotion_aff_token_at_render'), 'affpromos_settings', 'affpromos_settings_section_promotions' ); // add_settings_field( // 'affpromos_settings_promotion_auto_update', // __('Auto Update', AFFILIATE_PROMOTIONS_PLUG), // array(&$this, 'promotion_auto_update_render'), // 'affpromos_settings', // 'affpromos_settings_section_promotions' // ); add_settings_field( 'affpromos_settings_promotion_lifetime', __('Expiration', AFFILIATE_PROMOTIONS_PLUG), array(&$this, 'promotion_lifetime_render'), 'affpromos_settings', 'affpromos_settings_section_promotions' ); // add_settings_field( // 'affpromos_settings_aff_omit_offer_update', // __('Not update Offers', AFFILIATE_PROMOTIONS_PLUG), // array(&$this, 'promotion_aff_omit_offer_update_render'), // 'affpromos_settings', // 'affpromos_settings_section_promotions' // ); add_settings_field( 'affpromos_settings_promotion_auto_update', __('Sync everything', AFFILIATE_PROMOTIONS_PLUG), array(&$this, 'sync_full_fields_render'), 'affpromos_settings', 'affpromos_settings_section_promotions' ); add_settings_field( AFFILIATE_PROMOTIONS_PREFIX.'sync_promotion_fields', __('Sync Promotions', AFFILIATE_PROMOTIONS_PLUG), array(&$this, 'sync_promotion_fields_render'), 'affpromos_settings', 'affpromos_settings_section_promotions' ); add_settings_section( 'affpromos_offer_sync_setting', __('Sync Offers', AFFILIATE_PROMOTIONS_PLUG), null, 'affpromos_settings' ); add_settings_field( AFFILIATE_PROMOTIONS_PREFIX.'offer_limit_field', __('Offer Limit (<30)', AFFILIATE_PROMOTIONS_PLUG), array(&$this, 'offer_limit_field_renderer'), 'affpromos_settings', 'affpromos_offer_sync_setting' ); add_settings_field( AFFILIATE_PROMOTIONS_PREFIX.'offer_vendor_field', __('Vendor', AFFILIATE_PROMOTIONS_PLUG), array(&$this, 'offer_vendor_field_renderer'), 'affpromos_settings', 'affpromos_offer_sync_setting' ); add_settings_field( AFFILIATE_PROMOTIONS_PREFIX.'offer_cate_field', __('Category', AFFILIATE_PROMOTIONS_PLUG), array(&$this, 'offer_category_field_renderer'), 'affpromos_settings', 'affpromos_offer_sync_setting' ); } function validate_input_callback( $input ) { /* * Here you can validate (and manipulate) the user input before saving to the database */ return $input; } function section_quickstart_render() { ?>

  1. Add Post Element

[aff-promotions]

[aff-promotions category="group-xyz" type="type-abc" max="10" hide_expired="true"]

[aff-promotions template="grid" grid="4"] [affpromos_promotions template="line"]



[aff-offers category="group-xyz" type="type-abc" max="10" hide_expired="true"]

[aff-offers grid="3"]



[aff-product id="101" sticker="Best product ever" sub_header="You'll need this"]

[aff-product url="https://www.adayroi.com/apple-iphone-7-32gb-bac-hang-nhap-khau-p-dRa09-f1-2?pi=wayRB" sticker="Buy this" sub_header="Please !" ]


options[AFFILIATE_PROMOTIONS_AT_PREFIX.'offer_limit'] ) ? $this->options[AFFILIATE_PROMOTIONS_AT_PREFIX.'offer_limit'] : 30; ?> AFFILIATE_PROMOTIONS_PREFIX.'vendor', 'posts_per_page' =>-1, 'order' =>'ASC', 'orderby' =>'post_title', ]); $selected = ( isset ( $this->options[AFFILIATE_PROMOTIONS_AT_PREFIX.'offer_vendor'] ) ) ? $this->options[AFFILIATE_PROMOTIONS_AT_PREFIX.'offer_vendor'] : ''; ?> AFFILIATE_PROMOTIONS_PREFIX.'category','posts_per_page'=>-1,'order'=>'ASC','orderby'=>'post_title',]); $selected = ( isset ( $this->options[AFFILIATE_PROMOTIONS_AT_PREFIX.'offer_category'] ) ) ? $this->options[AFFILIATE_PROMOTIONS_AT_PREFIX.'offer_category'] : ''; ?>

-
-
*

* Last auto update:

options[AFFILIATE_PROMOTIONS_AT_PREFIX.'token'] ) ? $this->options[AFFILIATE_PROMOTIONS_AT_PREFIX.'token'] : 'XXX'; ?> options['auto_update_promotions'] ) && $this->options['auto_update_promotions'] == '1' ) ? 1 : 0; ?> /> options['hide_expired_promotions'] ) && $this->options['hide_expired_promotions'] == '1' ) ? 1 : 0; ?> /> options['aff_omit_offer_update'] ) && $this->options['aff_omit_offer_update'] == '1' ) ? 1 : 0; ?> /> options['text_01'] ) ) ? esc_attr( trim($this->options['text_01'] ) ) : '' ?> __('Please select...', AFFILIATE_PROMOTIONS_PLUG), '1' => __('Option One', AFFILIATE_PROMOTIONS_PLUG), '2' => __('Option Two', AFFILIATE_PROMOTIONS_PLUG), '3' => __('Option Three', AFFILIATE_PROMOTIONS_PLUG) ); $selected = ( isset ( $this->options['select_01'] ) ) ? $this->options['select_01'] : '0'; ?> options['checkbox_01'] ) && $this->options['checkbox_01'] == '1' ) ? 1 : 0; ?> /> options['text_02'] ) ) ? esc_attr( trim($this->options['text_02'] ) ) : '' ?>

" class="button-primary"> " class="button-primary">

{$section['title']}\n"; if ($section['callback']) call_user_func($section['callback'], $section); if (!isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']])) continue; echo '
'; echo $title; echo '
'; echo ''; do_settings_fields($page, $section['id']); echo '
'; echo '
'; echo '
'; } } function affpromos_logs_sections(){ $def_day = 7; $data = affpromos_query_logs_from($def_day); echo '
'; echo "

Logs

\n"; echo '
'; echo ''; foreach ($data as $item){ echo "
(". $item->time.") :: ".$item->message." | total: ". $item->amount ." items -- ". $item->status."

"; } if (count($data)==0){ echo 'No logs recorded !!'; } echo '
'; echo '
'; echo '
'; } function init_promotion_type() { $term_coupon = term_exists( 'Coupon', AFFILIATE_PROMOTIONS_PREFIX.'promotion_type' ); $term_promotion = term_exists( 'Promotion', AFFILIATE_PROMOTIONS_PREFIX.'promotion_type' ); if( $term_coupon == 0 || $term_coupon == null) { $type = wp_insert_term ('Coupon',AFFILIATE_PROMOTIONS_PREFIX.'promotion_type', array( 'description'=> 'coupon', 'slug' => 'coupon-type', ) ); } if( $term_promotion == 0 || $term_promotion == null) { $type = wp_insert_term ('Promotion',AFFILIATE_PROMOTIONS_PREFIX.'promotion_type', array( 'description'=> 'promotion', 'slug' => 'promotion-type', ) ); } } //---- Action for chuck function _defaul($obj,$def){ return isset($obj) ? $obj : $def; } function is_manual_update(){ return isset($_GET['action']) && $_GET['action'] === 'update_promotions'; } function do_admin_action() { if (is_manual_update()) { require_once AFFILIATE_PROMOTIONS_DIR . 'includes/apis/AccessTrade_Api.php'; $client = new AccessTrade_Api(); $client->run_full_update(); } } function admin_noti_mess ($mess, $type='success') { add_action( 'admin_notices', function() use ($mess,$type) { ?>

sync_type) ? $data->sync_type :''; $sync_type .= is_manual_update() ? 'manual_update' : 'auto_update'; $item = isset($data->item) ? $data->item : ''; $message = isset($data->message) ? $data->message : ''; $status = isset($data->status) ? $data->status : ''; $amount = isset($data->amount) ? $data->amount : 0; $sql = 'INSERT INTO ' . AFFILIATE_ACTION_LOG_TABLE . ' (`sync_type`,`item`,`message`,`status`,`amount`) VALUES (%s,%s,%s,%s,%d)'; $sql = $wpdb->prepare($sql, $sync_type, $item, $message, $status, $amount); $insert = $wpdb->query($sql); if (!$insert){ $create_table = affpromos_create_table_item_log(); if ($create_table!=false ) { $insert = $wpdb->query($sql); } } } function affpromos_create_table_item_log(){ global $wpdb; $sql = 'CREATE TABLE `' . AFFILIATE_ACTION_LOG_TABLE . '` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `sync_type` VARCHAR(50) , `item` VARCHAR(20), `message` VARCHAR(512) , `status` VARCHAR(20) , `amount` INT UNSIGNED, `time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`))'; $res = $wpdb->query($sql); return $res; } function affpromos_query_logs_from($days_ago){ global $wpdb; $sql = 'SELECT * FROM '.AFFILIATE_ACTION_LOG_TABLE.' WHERE (sync_type LIKE "summary_%" and time BETWEEN NOW() - INTERVAL '.$days_ago.' DAY AND NOW()) ORDER BY time DESC'; return $wpdb->get_results($sql); }