setup_bulk_options(); // Get all public posts. $post_types = get_post_types( array( 'public' => true, ) ); // Enable for all posts. foreach ( $post_types as $type ) { if ( 'attachment' !== $type && 'fl-theme-layout' !== $type ) { // add custom column. add_action( 'manage_' . $type . '_posts_columns', array( $this, 'add_custom_admin_column' ), 10, 1 ); // populate column. add_action( 'manage_' . $type . '_posts_custom_column', array( $this, 'manage_custom_admin_columns' ), 10, 2 ); } } } /** * Init bulk options */ function setup_bulk_options() { /** * Set metabox options * * @see http://php.net/manual/en/filter.filters.sanitize.php */ self::$meta_option = apply_filters( 'astra_meta_box_bulk_edit_options', array( 'ast-main-header-display' => array( 'sanitize' => 'FILTER_DEFAULT', ), 'ast-featured-img' => array( 'sanitize' => 'FILTER_DEFAULT', ), 'site-post-title' => array( 'sanitize' => 'FILTER_DEFAULT', ), 'site-sidebar-layout' => array( 'default' => 'default', 'sanitize' => 'FILTER_DEFAULT', ), 'site-content-layout' => array( 'default' => 'default', 'sanitize' => 'FILTER_DEFAULT', ), 'footer-sml-layout' => array( 'sanitize' => 'FILTER_DEFAULT', ), 'footer-adv-display' => array( 'sanitize' => 'FILTER_DEFAULT', ), 'theme-transparent-header-meta' => array( 'sanitize' => 'FILTER_DEFAULT', ), 'adv-header-id-meta' => array( 'sanitize' => 'FILTER_DEFAULT', ), 'stick-header-meta' => array( 'sanitize' => 'FILTER_DEFAULT', ), 'header-above-stick-meta' => array( 'sanitize' => 'FILTER_DEFAULT', ), 'header-main-stick-meta' => array( 'sanitize' => 'FILTER_DEFAULT', ), 'header-below-stick-meta' => array( 'sanitize' => 'FILTER_DEFAULT', ), ) ); } /** * Get metabox options */ public static function get_meta_option() { return self::$meta_option; } /** * Metabox Save * * @param number $post_id Post ID. * @return void */ function save_meta_box( $post_id ) { // Checks save status. $is_autosave = wp_is_post_autosave( $post_id ); $is_revision = wp_is_post_revision( $post_id ); $is_valid_nonce = ( isset( $_POST['astra_settings_bulk_meta_box'] ) && wp_verify_nonce( $_POST['astra_settings_bulk_meta_box'], basename( __FILE__ ) ) ) ? true : false; // Exits script depending on save status. if ( $is_autosave || $is_revision || ! $is_valid_nonce ) { return; } /** * Get meta options */ $post_meta = self::get_meta_option(); foreach ( $post_meta as $key => $data ) { // Sanitize values. $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT'; switch ( $sanitize_filter ) { case 'FILTER_SANITIZE_STRING': $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING ); break; case 'FILTER_SANITIZE_URL': $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL ); break; case 'FILTER_SANITIZE_NUMBER_INT': $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT ); break; default: $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT ); break; } // Store values. if ( $meta_value ) { update_post_meta( $post_id, $key, $meta_value ); } else { delete_post_meta( $post_id, $key ); } } } /** * Save bulk edit options. */ function save_post_bulk_edit() { $post_ids = ! empty( $_POST['post'] ) ? $_POST['post'] : array(); if ( ! empty( $post_ids ) && is_array( $post_ids ) ) { /** * Get meta options */ $post_meta = self::get_meta_option(); foreach ( $post_ids as $post_id ) { foreach ( $post_meta as $key => $data ) { // Sanitize values. $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_DEFAULT'; switch ( $sanitize_filter ) { case 'FILTER_SANITIZE_STRING': $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_STRING ); break; case 'FILTER_SANITIZE_URL': $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL ); break; case 'FILTER_SANITIZE_NUMBER_INT': $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT ); break; default: $meta_value = filter_input( INPUT_POST, $key, FILTER_DEFAULT ); break; } // Store values. if ( $meta_value ) { update_post_meta( $post_id, $key, $meta_value ); } else { delete_post_meta( $post_id, $key ); } } } } die(); } /** * Quick edit custom column to hold our data * * @param number $columns Columns. * @return array Column array. */ function add_custom_admin_column( $columns ) { $new_columns = array(); $new_columns['astra-settings'] = 'Astra Settings'; return array_merge( $columns, $new_columns ); } /** * Customize the data for our custom column, * It's here we pull in metadata info for each post. * These will be referred to in our JavaScript file for pre-populating our quick-edit screen * * @param string $column_name Column name. * @param number $post_id Post ID. * @return void */ function manage_custom_admin_columns( $column_name, $post_id ) { if ( 'astra-settings' == $column_name ) { $html = ''; $stored = get_post_meta( $post_id ); $meta = self::get_meta_option(); // Set stored and override defaults. foreach ( $stored as $key => $value ) { if ( array_key_exists( $key, $meta ) ) { $meta[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : ''; } } foreach ( $meta as $key => $value ) { $default_value = ''; $html .= '