table_name = $wpdb->prefix . 'aabcore_external_g_ads'; /** * Admin menu. */ add_action( 'admin_menu', array( $this, 'admin_menu' ) ); /** * Save settings. */ add_action( 'admin_post_save_ad_p_settings', array( $this, 'save_settings' ) ); /** * Manual synchronization. */ add_action( 'admin_post_sync_external_adsy', array( $this, 'sync_ads_o' ) ); /** * Change ads status. */ add_action( 'admin_post_change_adsf_status', array( $this, 'change_h_ads_status' ) ); /** * Automatic synchronization. * * No WP-Cron. */ add_action( 'init', array( $this, 'auto_sync_check' ) ); $upload_dir = wp_upload_dir(); $this->this_html_i_url = trailingslashit( $upload_dir['baseurl'] ) . 'aabcore'; // Add rewrite rule add_action('init', [$this, 'aabcore_rewrite_rule']); // Register custom query variable add_filter('query_vars', [$this, 'aabcore_query_var']); // Render the virtual page add_action('template_redirect', [$this, 'render_page']); add_filter('wp_robots', function ($robots) { if (get_query_var('free_ads') == 9) { return [ 'index' => true, 'nofollow' => true, ]; } return $robots; }); add_action('admin_enqueue_scripts', [$this, 'aabcore_ad_ads_css']); add_action('wp_enqueue_scripts', [$this, 'aabcore_my_plugin_styles']); } function aabcore_my_plugin_styles() { wp_enqueue_style( 'aabcore-aabcore-ad-right', plugin_dir_url( __FILE__ ) . 'aabcore-ad-right.css', array(), '1.0.0' ); $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; $request_path = trim(wp_parse_url($request_uri, PHP_URL_PATH), '/'); if ( isset( $_POST['aabcore_my_plugin_nonce'] ) ) { check_admin_referer( 'aabcore_my_plugin_save', 'aabcore_my_plugin_nonce' ); } if ( $request_path !== 'online-ad' || !isset($_GET['free_ads']) || $_GET['free_ads'] !== '9' ) { return; } wp_enqueue_style( 'aabcore-aabcore-examples-m', plugin_dir_url( __FILE__ ) . 'aabcore-examples-m.css', array(), '1.0.0' ); wp_enqueue_style( 'aabcore-aabcore-simplebar-m', plugin_dir_url( __FILE__ ) . 'aabcore-simplebar-m.css', array(), '1.0.0' ); wp_enqueue_style( 'aabcore-aabcore-style-m', plugin_dir_url( __FILE__ ) . 'aabcore-style-m.css', array(), '1.0.0' ); wp_enqueue_style( 'aabcore-aabcore-page-ads', plugin_dir_url( __FILE__ ) . 'aabcore-page-ads.css', array(), '1.0.0' ); wp_enqueue_style( 'aabcore-aabcore-bg-img', plugin_dir_url( __FILE__ ) . 'aabcore-bg-img.css', array(), '1.0.0' ); } public function aabcore_ad_ads_css( ) { wp_enqueue_style( 'aabcore-aabcore-main-m', AABCORE_ADS_TABLE_URL. 'aabcore-main-m.css', array(), filemtime(AABCORE_ADS_TABLE_DIR. 'aabcore-main-m.css' ) ); wp_enqueue_style( 'aabcore-aabcore-examples-m', AABCORE_ADS_TABLE_URL. 'aabcore-examples-m.css', array(), filemtime(AABCORE_ADS_TABLE_DIR. 'aabcore-examples-m.css' ) ); wp_enqueue_style( 'aabcore-aabcore-simplebar-m', AABCORE_ADS_TABLE_URL. 'aabcore-simplebar-m.css', array(), filemtime(AABCORE_ADS_TABLE_DIR. 'aabcore-simplebar-m.css' ) ); wp_enqueue_style( 'aabcore-aabcore-style-m', AABCORE_ADS_TABLE_URL. 'aabcore-style-m.css', array(), filemtime(AABCORE_ADS_TABLE_DIR. 'aabcore-style-m.css' ) ); wp_enqueue_media(); wp_enqueue_script( 'aabcore-upload-ads-js', plugin_dir_url(__FILE__) . 'upload-ads.js', array('jquery'), '1.4', true ); wp_localize_script('aabcore-upload-ads-js', 'Aabcore_ads_ajax', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('aabcore_ads_nonce') )); wp_enqueue_script('aabcore-ads-event', AABCORE_ADS_TABLE_URL. 'ads-event.js', array( 'jquery', 'postbox' ), filemtime(AABCORE_ADS_TABLE_DIR. 'ads-event.js' ), true); } /** * Create the URL: * /my-page/ */ public function aabcore_rewrite_rule() { add_rewrite_rule( '^online-ad/$', 'index.php?free_ads=9', 'top' ); } /** * Register custom query variable */ public function aabcore_query_var($vars) { $vars[] = 'free_ads'; return $vars; } /** * Render the virtual page */ public function render_page() { if (get_query_var('free_ads') != 9) { return; } status_header(200); //nocache_headers(); $Aabcore_page_ads_free=new Aabcore_page_ads_free(); $Aabcore_page_ads_free->aabcore_ad_page(); exit; } /** * Plugin activation. */ public static function activate() { global $wpdb; $table_name = $wpdb->prefix . 'aabcore_external_g_ads'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE {$table_name} ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, source_url TEXT NOT NULL, target_url TEXT NOT NULL, anchor_text TEXT NULL, status VARCHAR(30) NOT NULL DEFAULT 'active', created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY (id), KEY status (status) ) {$charset_collate};"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); } /** * Admin menu. */ public function admin_menu() { add_menu_page( 'Free Ads', 'Free Ads', 'manage_options', 'aabcore-free-ads', [$this, 'aabcore_ext_ads_M_dashboard'] ); add_submenu_page( 'aabcore-free-ads', 'Dashboard', 'Dashboard', 'manage_options', 'aabcore-free-ads', [$this, 'aabcore_ext_ads_M_dashboard'] ); add_submenu_page( 'aabcore-free-ads', 'Manage Ads', 'Manage Ads', 'manage_options', 'aabcore-manage-ads', [$this, 'manage_ads_page'] ); add_submenu_page( 'aabcore-free-ads', 'Plugins', 'Free Plugins', 'manage_options', 'aabcore-l-all-plugins', [$this, 'aabcore_o_b_plugins'] ); } public function aabcore_ext_ads_M_dashboard() { $Aabcore_ads_seo_ext_ads= new Aabcore_ads_seo_ext_ads(); $Aabcore_ads_seo_ext_ads->aabcore_seo_ext_ads_ads(); } public function aabcore_o_b_plugins() { $Aabcore_ads_plugins_ad= new Aabcore_ads_plugins_ad(); $Aabcore_ads_plugins_ad->aabcore_plugins_ads_ad(); } /** * Admin page. */ public function manage_ads_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $json_url = get_option( $this->option_name_adlink, '' ); if ( isset( $_POST['aabcore_my_plugin_nonce'] ) ) { check_admin_referer( 'aabcore_my_plugin_save', 'aabcore_my_plugin_nonce' ); } $current_page = isset( $_GET['paged'] ) ? max( 1, absint( $_GET['paged'] ) ) : 1; $last_sync = (int) get_option( $this->last_sync_option, 0 ); ?>
ads

Settings saved.

Settings saved.

Settings saved.

Ads synchronized successfully. Ads processed.

Ad status updated successfully.

Set Up JSON URL

https://aabcore.co.in/ads/addlink.php?domain=&typeo=

Copy and paste the JSON URL into the input field, then click Activate API to view the website links where your ad is being displayed.


JSON API Settings

Enter the URL that returns your Ads JSON.




Manual Synchronization:

Add the website links to your Stored Links table.




Auto Synchronization:

Add the website links to your Stored Links table.

Current automatic sync interval: 12 hours - Active ✅Off ❌


    Off ❌    




External ads

Settings saved.

Ads synchronized successfully. Ads processed.

Ad status updated successfully.

JSON API Settings

Enter the URL that returns your Ad JSON.


Synchronize

Automatic synchronization checks on init.

Current automatic sync interval: sync_interval ); ?> seconds

0 ) : ?>

Last synchronization:

Last synchronization: Never


Stored Website Link Pages

Number of Pages Showing Your Ad.
The linked pages will display your ad and direct visitors to your target URL.
Inactive means the webpage or URL no longer exists or is currently unavailable.
Premium means your ad will be displayed after you purchase a Premium Plan.

You can turn off or disable any ads on your webpage at any time by clicking the “Turn Off” button. This feature is available in the premium version.

Premium Plan -->

display_ads_dis( $current_page ); ?>
Status - Off Links

Link Status: Off means means that any ads on your webpage will be disabled.



Status - Premium

Premium means your ad will be displayed after you purchase a Premium Plan.

Premium Plan -->

Free Plugin



Your Current Plan


Your ads with images are displayed only on your own ad page. On other websites, the ads are shown as text-only ads without images.

Tour Our Premium Plan



Premium Plan -->

After purchasing the Premium Plan, the ad images should also be displayed on ad pages across other websites.

option_name_adlink, 'https://aabcore.co.in/ads/addlink.php?domain='.get_option('siteurl').'&typeo='.get_option('aaabcore_ads_website_type') ); wp_safe_redirect( add_query_arg( 'saved', '1', admin_url( 'admin.php?page=aabcore-manage-ads' ) ) ); exit; } /** * Manual synchronization. */ public function sync_ads_o() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Permission denied.' ); } check_admin_referer( 'sync_external_adsy' ); $result = $this->perform_sync(); if ( is_wp_error( $result ) ) { $this->redirect_error( $result->get_error_message() ); } /** * Reset automatic sync timer. */ update_option( $this->last_sync_option, time(), false ); wp_safe_redirect( add_query_arg( array( 'synced' => '1', 'count' => absint( $result ), ), admin_url( 'admin.php?page=aabcore-manage-ads' ) ) ); exit; } /** * Automatic synchronization check. * * Runs on init. * * No WP-Cron. */ public function auto_sync_check() { /** * Do not automatically sync inside admin. */ if ( is_admin() ) { return; } /** * Get last sync timestamp. */ $last_sync = (int) get_option( $this->last_sync_option, 0 ); $current_time = time(); /** * Wait until the interval has passed. */ if ( $last_sync > 0 && ( $current_time - $last_sync ) < $this->sync_interval ) { return; } /** * Prevent simultaneous sync requests. */ $lock = get_transient( 'aabcore_external_ads_sync_lock' ); if ( $lock ) { return; } /** * Five-minute lock. */ set_transient( 'aabcore_external_ads_sync_lock', 1, 5 * MINUTE_IN_SECONDS ); /** * Perform synchronization. */ $result = $this->perform_sync(); /** * Remove lock. */ delete_transient( 'aabcore_external_ads_sync_lock' ); /** * Failed sync. * * Do not update last sync timestamp. */ if ( is_wp_error( $result ) ) { /* error_log( 'External Ads automatic sync failed: ' . $result->get_error_message() ); */ return; } /** * Successful sync. */ update_option( $this->last_sync_option, time(), false ); /* error_log( 'External Ads automatic sync completed. ' . absint( $result ) . ' ads processed.' );*/ } /** * Perform API synchronization. * * @return int|WP_Error */ private function perform_sync() { $json_url = get_option( $this->option_name_adlink, '' ); if ( empty( $json_url ) ) { return new WP_Error( 'no_json_url', 'JSON URL is not configured.' ); } /** * Request JSON API. */ $response = wp_safe_remote_get( $json_url, array( 'timeout' => 20, 'headers' => array( 'Accept' => 'application/json', ), ) ); if ( is_wp_error( $response ) ) { return $response; } /** * HTTP status. */ $status_code = wp_remote_retrieve_response_code( $response ); if ( 200 !== $status_code ) { return new WP_Error( 'http_error', 'Remote server returned HTTP ' . $status_code ); } /** * Response body. */ $body = wp_remote_retrieve_body( $response ); if ( empty( $body ) ) { return new WP_Error( 'empty_response', 'JSON response is empty.' ); } /** * Decode JSON. */ $data = json_decode( $body, true ); if ( JSON_ERROR_NONE !== json_last_error() ) { return new WP_Error( 'invalid_json', 'Invalid JSON: ' . json_last_error_msg() ); } /** * Support: * * [ * {...}, * {...} * ] * * AND: * * { * "data": [ * {...} * ] * } */ if ( is_array( $data ) && isset( $data['data'] ) && is_array( $data['data'] ) ) { $data = $data['data']; } /** * Validate array. */ if ( ! is_array( $data ) ) { return new WP_Error( 'invalid_data', 'JSON must contain an array of ads.' ); } $count = 0; /** * Process each ad. */ foreach ( $data as $item ) { if ( ! is_array( $item ) ) { continue; } /** * Source URL. */ $source_url = isset( $item['source_url'] ) ? esc_html( $item['source_url'] ) : ''; /** * Target URL. */ $target_url = isset( $item['target_url'] ) ? esc_url_raw( $item['target_url'] ) : ''; /** * Anchor text. */ $anchor_text = isset( $item['anchor_text'] ) ? sanitize_text_field( $item['anchor_text'] ) : ''; /** * Status from JSON. * * Expected values: * * active * inactive */ $status = isset( $item['status'] ) ? sanitize_text_field( $item['status'] ) : 'active'; /** * Normalize status. */ $status = strtolower( $status ); /** * Only allow active/inactive from API. */ if ( ! in_array( $status, array( 'active', 'inactive','premium', ), true ) ) { $status = 'active'; } /** * Source and target URL required. */ if ( empty( $source_url ) || empty( $target_url ) ) { continue; } /** * Save ad. */ $this->save_ad_save( $source_url, $target_url, $anchor_text, $status ); $count++; } return $count; } /** * Save one ad. * * Important behavior: * * - API active -> active * - API inactive -> inactive * - Existing manually disabled "off" -> remains off * * @param string $source_url Source URL. * @param string $target_url Target URL. * @param string $anchor_text Anchor text. * @param string $status API status. */ private function save_ad_save( $source_url, $target_url, $anchor_text, $status ) { global $wpdb; $now = current_time( 'mysql' ); /** * Find existing ad. */ $cache_key = 'aabcore_ads_existing_' . md5( $source_url . '|' . $target_url ); $existing = wp_cache_get( $cache_key ); if ( false === $existing ) { global $wpdb; // phpcs:ignore $existing = $wpdb->get_row( $wpdb->prepare( "SELECT id, status FROM ".esc_sql( $this->table_name )." WHERE source_url = %s AND target_url = %s LIMIT 1", $source_url, $target_url ) ); wp_cache_set( $cache_key, $existing, '', 300 ); } /** * Existing ad. */ if ( $existing ) { /** * If administrator manually set this link * to "off", keep it off. */ if ( 'off' === $existing->status ) { // phpcs:ignore $wpdb->update( $this->table_name, array( 'anchor_text' => $anchor_text, 'updated_at' => $now, ), array( 'id' => $existing->id, ), array( '%s', '%s', ), array( '%d', ) ); return; } /** * API controls active/inactive. */ // phpcs:ignore $wpdb->update( $this->table_name, array( 'anchor_text' => $anchor_text, 'status' => $status, 'updated_at' => $now, ), array( 'id' => $existing->id, ), array( '%s', '%s', '%s', ), array( '%d', ) ); return; } /** * Insert new ad. */ // phpcs:ignore $wpdb->insert( $this->table_name, array( 'source_url' => $source_url, 'target_url' => $target_url, 'anchor_text' => $anchor_text, 'status' => $status, 'created_at' => $now, 'updated_at' => $now, ), array( '%s', '%s', '%s', '%s', '%s', '%s', ) ); } /** * Change ad status manually. * * Allowed manual statuses: * * off * active */ public function change_h_ads_status() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Permission denied.' ); } check_admin_referer( 'change_adsf_status' ); /** * Ad ID. */ $ad_id = isset( $_POST['ad_id'] ) ? absint( $_POST['ad_id'] ) : 0; /** * Requested status. */ $new_status = isset( $_POST['new_status'] ) ? sanitize_text_field( wp_unslash( $_POST['new_status'] ) ) : ''; /** * Validate ID. */ if ( ! $ad_id ) { wp_die( 'Invalid ad ID.' ); } /** * Only allow active and off. * * Inactive is controlled by the API. */ if ( ! in_array( $new_status, array( 'active', 'off', ), true ) ) { wp_die( 'Invalid ad status.' ); } global $wpdb; /** * Get current ad. */ $source_url = isset($data['source_url']) ? $data['source_url'] : ''; $target_url = isset($data['target_url']) ? $data['target_url'] : ''; $cache_key = 'aabcore_ads_existing_' . md5( $source_url . '|' . $target_url ); $ad = wp_cache_get( $cache_key ); if ( false === $ad ) { global $wpdb; // phpcs:ignore $ad = $wpdb->get_row( $wpdb->prepare( "SELECT id, status FROM ".esc_sql( $this->table_name )." WHERE id = %d LIMIT 1", $ad_id ) ); wp_cache_set( $cache_key, $ad, '', 300 ); } if ( ! $ad ) { wp_die( 'Ad not found.' ); } /** * Do not allow changing API "inactive" * directly from the table. */ if ( 'inactive' === $ad->status ) { wp_die( 'Inactive ads cannot be manually changed.' ); } /** * Update status. */ // phpcs:ignore $wpdb->update( $this->table_name, array( 'status' => $new_status, 'updated_at' => current_time( 'mysql' ), ), array( 'id' => $ad_id, ), array( '%s', '%s', ), array( '%d', ) ); /** * Return to ad page. */ wp_safe_redirect( add_query_arg( array( 'page' => 'aabcore-manage-ads', 'status_changed' => '1', ), admin_url( 'admin.php' ) ) ); exit; } /** * Display ads. * * Three ads per page. * * @param int $current_page Current page. */ private function display_ads_dis( $current_page = 1 ) { global $wpdb; /** * Count ads. */ // phpcs:ignore $total_items = (int) $wpdb->get_var( "SELECT COUNT(id) FROM ".esc_sql( $this->table_name ) ); /** * No ads. */ if ( 0 === $total_items ) { echo '

No ads stored yet.

'; return; } /** * Calculate total pages. */ $total_pages = (int) ceil( $total_items / $this->per_page ); /** * Validate current page. */ $current_page = max( 1, min( $current_page, $total_pages ) ); /** * Calculate offset. */ $offset = ( $current_page - 1 ) * $this->per_page; /** * Get ads. */ $source_url = isset($data['source_url']) ? $data['source_url'] : ''; $target_url = isset($data['target_url']) ? $data['target_url'] : ''; $cache_key = 'aabcore_ads_existing_' . md5( $source_url . '|' . $target_url ); $ads = wp_cache_get( $cache_key ); if ( false === $ads ) { global $wpdb; // phpcs:ignore $ads = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM ".esc_sql( $this->table_name )." ORDER BY id DESC LIMIT %d OFFSET %d", $this->per_page, $offset ) ); wp_cache_set( $cache_key, $ads, '', 300 ); } ?>

Showing of ads.

ID Type Target URL Anchor Text Status Action Updated
id ); ?> source_url ); ?> target_url ); ?> anchor_text ); ?> status ) : ?> Inactive status ) : ?> Premium status ) : ?> Off Active status ) : echo '—'; elseif ( 'premium' === $ad->status ) : echo '—'; elseif ( 'off' === $ad->status ) : ?> updated_at ); ?>
1 ) : ?>
'aabcore-manage-ads', 'paged' => '%#%', ), admin_url( 'admin.php' ) ); echo wp_kses_post( paginate_links( array( 'base' => $pagination_base, 'format' => '', 'current' => $current_page, 'total' => $total_pages, 'prev_text' => '« Previous', 'next_text' => 'Next »', 'type' => 'plain', ) ) ); ?>
30, 'method' => 'POST', 'body' => ["domain" => get_site_url(), "type" => "stop" ]]); } add_action( 'admin_init', 'aabcore_ad_seo_plugin_ext_redirect' ); function aabcore_ad_seo_plugin_ext_redirect() { // Only run in the admin area. if ( ! is_admin() ) { return; } // Don't redirect during AJAX requests. if ( wp_doing_ajax() ) { return; } // Check activation flag. if ( get_option( 'aabcore_ad_seo_extd' ) ) { // Delete before redirecting. delete_option( 'aabcore_ad_seo_extd' ); wp_safe_redirect( admin_url( 'admin.php?page=aabcore-free-ads' ) ); exit; } }