run(); } public function run() { add_action( 'add_meta_boxes', array( $this, 'ao_metabox_add_box' ) ); add_action( 'save_post', array( $this, 'ao_metabox_save' ) ); add_action( 'wp_ajax_ao_metabox_ccss_addjob', array( $this, 'ao_metabox_generateccss_callback' ) ); } public function ao_metabox_add_box() { $screens = array( 'post', 'page', // add extra types e.g. product or ... ? ); $screens = apply_filters( 'autoptimize_filter_metabox_screens', $screens ); foreach ( $screens as $screen ) { add_meta_box( 'ao_metabox', esc_html__( 'Autoptimize this page', 'autoptimize' ), array( $this, 'ao_metabox_content' ), $screen, 'side' ); } } /** * Prints the box content. * * @param WP_Post $post The object for the current post/page. */ function ao_metabox_content( $post ) { // phpcs:disable Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace wp_nonce_field( 'ao_metabox', 'ao_metabox_nonce' ); $ao_opt_value = $this->check_ao_opt_sanity( get_post_meta( $post->ID, 'ao_post_optimize', true ) ); $_ao_meta_sub_opacity = ''; if ( 'on' !== $ao_opt_value['ao_post_optimize'] ) { $_ao_meta_sub_opacity = 'opacity:.33;'; } ?>

/>

'; ?> />

'; ?> />

'; ?> />

'; ?> />

 

post_type ) { $_type = 'is_page'; } // if CSS opt and inline & defer are on and if we have a slug, the button can be active. if ( false !== $_slug && 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_css', false ) && 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer', false ) && ! empty( apply_filters( 'autoptimize_filter_ccss_key', autoptimizeOptionWrapper::get_option( 'autoptimize_ccss_key', false ) ) ) && '2' === autoptimizeOptionWrapper::get_option( 'autoptimize_ccss_keyst', false ) ) { $_generate_disabled = false; } ?>

criticalcss(); $_result = $criticalcss->enqueue( '', $path, $type ); if ( $_result ) { $response['code'] = '200'; $response['string'] = $path . ' added to job queue.'; } else { $response['code'] = '404'; $response['string'] = 'could not add ' . $path . ' to job queue.'; } } else { $response['code'] = '500'; $response['string'] = 'nok'; } // Dispatch respose. echo json_encode( $response ); // Close ajax request. wp_die(); } public function get_metabox_default_values() { $ao_metabox_defaults = array( 'ao_post_optimize' => 'on', 'ao_post_js_optimize' => 'on', 'ao_post_css_optimize' => 'on', 'ao_post_ccss' => 'on', 'ao_post_lazyload' => 'on', 'ao_post_preload' => '', ); return $ao_metabox_defaults; } public function check_ao_opt_sanity( $ao_opt_val ) { if ( empty( $ao_opt_val ) || ! is_array( $ao_opt_val ) ) { $ao_opt_val = $this->get_metabox_default_values(); } else { foreach ( array( 'ao_post_optimize', 'ao_post_js_optimize', 'ao_post_css_optimize', 'ao_post_ccss', 'ao_post_lazyload' ) as $key ) { if ( ! array_key_exists( $key, $ao_opt_val ) ) { $ao_opt_val[ $key ] = 'off'; } } } return $ao_opt_val; } }