true, '__back_compat_meta_box' => true, ) ); } /** * @param $post * callback function for backword compatibility / classic editor plugin installed. */ public function exclude_from_cache_metabox( $post ) { wp_nonce_field( basename( __FILE__ ), 'oct-exclude-from-cache' ); $excluded_from_cache = get_post_meta( $post->ID, '_oct_exclude_from_cache', true ); ?>
'PURGE' ) ); if ( ! isset( $_POST['oct-exclude-from-cache'] ) || ! wp_verify_nonce( $_POST['oct-exclude-from-cache'], basename( __FILE__ ) ) ) { return $post_id; } if ( isset( $_POST['oc-exclude-from-cache'] ) ) { update_post_meta( $post_id, '_oct_exclude_from_cache', true ); } else { update_post_meta( $post_id, '_oct_exclude_from_cache', false ); } } /** * */ public function oc_block_script_enqueue() { global $pagenow; if ( 'post.php' !== $pagenow ) { return; } wp_enqueue_script( 'block-metabox', plugins_url( '../assets/js/blocks/block-metabox.js', __FILE__ ), array( 'wp-edit-post' ) ); wp_localize_script( 'block-metabox', 'blockObject', array( 'label' => 'Exclude from cache', 'excludeText' => 'This %s will be excluded from cache.', 'includeText' => 'This %s will be cached.', ) ); } /** * registers post meta for exclude cache */ public function oc_vcache_register_post_meta() { if ( function_exists( 'register_post_meta' ) ) { register_post_meta( '', '_oct_exclude_from_cache', array( 'show_in_rest' => true, 'single' => true, 'type' => 'boolean', 'auth_callback' => function () { return current_user_can( 'edit_posts' ); }, ) ); } else { $this->oc_register_post_meta( '', '_oct_exclude_from_cache', array( 'show_in_rest' => true, 'single' => true, 'type' => 'boolean', 'auth_callback' => function () { return current_user_can( 'edit_posts' ); }, ) ); } } /** * @param $post_type * @param $meta_key * @param array $args * @return bool * For backward compatibility with versions older than WP 4.9 */ public function oc_register_post_meta( $post_type, $meta_key, array $args ) { $args['object_subtype'] = $post_type; return register_meta( 'post', $meta_key, $args ); } }