1, 'bypass' => 1, 'beforePostTag' => '', 'afterPostTag' => '', 'adsWithinTag' => '' ), null, 'yes' ); if ( is_admin() ) { // Admin actions. add_action( 'admin_menu', 'adblade_menu' ); add_action( 'admin_init', 'register_adblade_settings' ); } /** * Add "Adblade" to the admin menu */ function adblade_menu() { add_options_page( 'Adblade Options', 'Adblade', 'manage_options', 'adblade', ADBLADE_OPTIONS ); } /** * Register plugin settings. */ function register_adblade_settings() { $options = get_option( ADBLADE_OPTIONS ); if (!array_key_exists('version', $options) || $options['version'] < ADBLADE_DB_VERSION) { global $wp_rewrite; // update the rewrite rules add_rewrite_rule( '^' . ADBLADE_PREFIX . '/js/main.js', 'index.php?adblade-catch=js/log-ab.php', 'top' ); add_rewrite_rule( '^' . ADBLADE_PREFIX . '/js/bootstrap.js', 'index.php?adblade-catch=js/blockadblock.js', 'top' ); add_rewrite_rule( '^' . ADBLADE_PREFIX . '/js/jquery.js', 'index.php?adblade-catch=show', 'top' ); add_rewrite_rule( '^' . ADBLADE_PREFIX . '/index.html', 'index.php?adblade-catch=impsc', 'top' ); add_rewrite_rule( '^' . ADBLADE_PREFIX . '/images/.+', 'index.php?adblade-catch=image', 'top' ); add_rewrite_rule( '^' . ADBLADE_PREFIX . '/css/.+', 'index.php?adblade-catch=css', 'top' ); add_rewrite_rule( '^' . ADBLADE_PREFIX . '/(.*)', 'index.php?adblade-catch=$matches[1]', 'top' ); $wp_rewrite->flush_rules( false ); $options['version'] = ADBLADE_DB_VERSION; update_option( ADBLADE_OPTIONS, $options, 'yes' ); } register_setting( 'adblade-group', ADBLADE_OPTIONS, 'adblade_options_sanitize' ); // General settings. add_settings_section( 'general-settings', 'General Settings', 'general_settings_callback', 'adblade-publisher-tools' ); add_settings_field( 'ga', 'Enable Google Analytics event logging', 'ga_callback', 'adblade-publisher-tools', 'general-settings' ); add_settings_field( 'bypass', 'Attempt to bypass ad blockers', 'bypass_callback', 'adblade-publisher-tools', 'general-settings' ); // Ad tag settings. add_settings_section( 'ad-tag-settings', 'Ad Tag Settings', 'ad_tag_settings_callback', 'adblade-publisher-tools' ); add_settings_field( 'beforePostTag', 'Before Post Ad Tag', 'before_post_ad_tag_callback', 'adblade-publisher-tools', 'ad-tag-settings' ); add_settings_field( 'adsWithinTag', '[AdsWithin] Short Code Ad Tag', 'ads_within_ad_tag_callback', 'adblade-publisher-tools', 'ad-tag-settings' ); add_settings_field( 'afterPostTag', 'After Post Ad Tag', 'after_post_ad_tag_callback', 'adblade-publisher-tools', 'ad-tag-settings' ); } /** * Ad tag settings callback. */ function ad_tag_settings_callback() { echo 'These fields are optional. You can leave them blank and add tags however you wish.'; } /** * General settings callback. */ function general_settings_callback() { // Don't do anything here. } /** * Output the settings input for Google Analytics. */ function ga_callback() { $options = get_option( ADBLADE_OPTIONS ); echo ''; } /** * Output the settings input for bypassing ad blockers. */ function bypass_callback() { $options = get_option( ADBLADE_OPTIONS ); echo ''; } /** * Output the settings input for the pre-post ad tag. */ function before_post_ad_tag_callback() { $options = get_option( ADBLADE_OPTIONS ); printf( '', $options['beforePostTag'] ); } /** * Output the settings input for the post-post ad tag. */ function after_post_ad_tag_callback() { $options = get_option( ADBLADE_OPTIONS ); printf( '', $options['afterPostTag'] ); } /** * Output the settings input for the [AdsWithin] ad tag. */ function ads_within_ad_tag_callback() { $options = get_option( ADBLADE_OPTIONS ); printf( '', $options['adsWithinTag'] ); } /** * Sanitize the form input. * @param array $input - The form input. * @return The sanitized input. */ function adblade_options_sanitize( $input ) { $clean = array(); $clean['ga'] = (intval( $input['ga'] ) === 1) ? 1 : 0; $clean['bypass'] = (intval( $input['bypass'] ) === 1) ? 1 : 0; $clean['beforePostTag'] = $input['beforePostTag']; $clean['adsWithinTag'] = $input['adsWithinTag']; $clean['afterPostTag'] = $input['afterPostTag']; return $clean; } /** * Build the admin options form. */ function adblade_options() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); } ?>