get_ads( $args ); } /** * WP Ajax for front and backend. */ function dfads_ajax_load_ads(){ echo dfads( $_REQUEST ); die; } add_action('wp_ajax_nopriv_dfads_ajax_load_ads', 'dfads_ajax_load_ads'); add_action('wp_ajax_dfads_ajax_load_ads', 'dfads_ajax_load_ads'); /** * Add shortcode functionality to Text widget. */ function dfads_enable_shortcodes_in_text_widget() { $output = get_option( 'dfads-settings' ); if ( isset( $output['dfads_enable_shortcodes_in_widgets'] ) ) { add_filter( 'widget_text', 'do_shortcode' ); } } add_action( 'init', 'dfads_enable_shortcodes_in_text_widget' ); /** * Add _dfads_impression_count custom field to new post. */ function dfads_save_post( $post_id ) { $slug = 'dfads'; $_POST += array("{$slug}_edit_nonce" => ''); if ( $slug != $_POST['post_type'] ) { return; } if ( !current_user_can( 'edit_post', $post_id ) ) { return; } if ( !wp_verify_nonce( $_POST["{$slug}_edit_nonce"], plugin_basename( __FILE__ ) ) ) { return; } if ( isset( $post_id ) ) { add_post_meta($post_id, DFADS_METABOX_PREFIX.'impression_count', 0); } } add_action( 'save_post', 'dfads_save_post' ); /** * Add shortcode functionality. */ function dfads_shortcode( $atts ) { return dfads( $atts['params'] ); } add_shortcode( 'dfads', 'dfads_shortcode' ); /** * Add settings link on plugin page. */ function dfads_settings_link( $links ) { $settings_link = 'Settings'; array_unshift( $links, $settings_link) ; return $links; } add_filter( 'plugin_action_links_'.plugin_basename(__FILE__), 'dfads_settings_link' ); /** * Add plugin meta links on plugin page. */ function dfads_plugin_row_meta( $links, $file ) { $plugin = plugin_basename( __FILE__ ); if ( $file == $plugin ) { return array_merge( $links, array( 'Documentation' ) ); } return $links; } add_filter( 'plugin_row_meta', 'dfads_plugin_row_meta', 10, 2 ); /** * Add help drop down menu to plugin's settings page. */ function dfads_help( $contextual_help, $screen_id, $screen ) { global $dfads_plugin_hook; if ($screen_id == $dfads_plugin_hook) { $contextual_help = '

Documentation

'; } return $contextual_help; } add_filter( 'contextual_help', 'dfads_help', 10, 3 ); /** * Remove "Visual" editor from "Add Ad" page. */ function dfads_user_can_richedit( $default ) { global $post; if ( DFADS_CONTEXT == get_post_type( $post ) ) { return false; } return $default; } add_filter( 'user_can_richedit', 'dfads_user_can_richedit' ); /** * Hide some meta boxes from "Add Ad" page. */ function dfads_default_hidden_meta_boxes( $hidden, $screen ) { if ( DFADS_CONTEXT == $screen->id ) { $hidden[] = 'postcustom'; //hide custom fields. $hidden[] = 'pageparentdiv'; //hide page attributes fields. $hidden[] = 'postimagediv'; // hide featured image. $hidden[] = 'revisionsdiv'; // hide revisions. } return $hidden; } add_filter( 'default_hidden_meta_boxes', 'dfads_default_hidden_meta_boxes', 10, 2 ); /** * Delete transient data related to DFADS * https://github.com/Seebz/Snippets/tree/master/Wordpress/plugins/purge-transients */ function dfads_purge_transients() { global $wpdb; $older_than='10 seconds'; $older_than_time = strtotime( '-' . $older_than ); if ( $older_than_time > time() || $older_than_time < 1 ) { return false; } $transients = $wpdb->get_col( $wpdb->prepare( " SELECT REPLACE(option_name, '_transient_timeout_', '') AS transient_name FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_timeout\_dfad\__%%' AND option_value < %s ", $older_than_time ) ); foreach($transients as $transient) { get_transient( $transient ); } update_option('dfads_transient_data_deleted_time', time()); } add_action( 'shutdown', 'dfads_purge_transients' );