capability = 'administrator'; $this->settings_page = awpp_get_instance()->prefix . '-settings'; $this->settings_option = AWPP_SETTINGS_OPTION; $this->settings_group = $this->settings_key . '-group'; $this->settings_section = $this->settings_key . '-section'; $this->adminbar_id = awpp_get_instance()->prefix . '_adminbar'; $this->select_choices['serverpush'] = [ 'disabled' => __( 'Disabled', 'awpp' ), 'php' => __( 'PHP', 'awpp' ), 'htaccess' => __( '.htaccess', 'awpp' ), ]; $this->select_choices['loadcss'] = [ 'disabled' => __( 'Disabled', 'awpp' ), 'classic' => __( 'Classic', 'awpp' ), //'api' => __( 'API (beta)', 'awpp' ), ]; $this->options = get_option( $this->settings_option ); } public function run() { add_action( 'admin_action_awpp_beta_mode', [ $this, 'awpp_beta_mode_option' ] ); add_action( 'admin_menu', [ $this, 'add_menu_page' ] ); add_action( 'admin_init', [ $this, 'register_settings' ] ); add_action( 'admin_bar_menu', [ $this, 'add_toolbar' ], 90 ); add_action( 'admin_init', [ $this, 'http2_check' ] ); add_action( 'awpp_on_activate', [ $this, 'set_default_settings' ] ); add_action( 'awpp_on_update', [ $this, 'set_default_settings' ] ); } public function add_menu_page() { add_submenu_page( AWPP_SETTINGS_PARENT, awpp_get_instance()->name, awpp_get_instance()->name, $this->capability, $this->settings_page, [ $this, 'register_settings_page' ] ); } public function register_settings_page() { ?>

name; ?>

settings_option . 'errors' ); settings_fields( $this->settings_group ); do_settings_sections( $this->settings_page ); submit_button(); ?>

Nico Martin - Say Hello GmbH' ); ?>

settings_section; register_setting( $this->settings_group, $this->settings_option, [ $this, 'sanitize' ] ); register_setting( $this->settings_group, $this->settings_option, [ $this, 'update_file' ] ); add_settings_section( $section, __( 'Settings', 'awpp' ), [ $this, 'print_section_info' ], $this->settings_page ); add_settings_field( 'scripts_to_footer', __( 'Move all scripts to footer', 'awpp' ), [ $this, 'scripts_to_footer_callback' ], $this->settings_page, $section ); add_settings_field( 'minify', __( 'Minify CSS and JS Files', 'awpp' ), [ $this, 'minify_callback' ], $this->settings_page, $section ); add_settings_field( 'loadcss', __( 'Load CSS async', 'awpp' ), [ $this, 'loadcss_callback' ], $this->settings_page, $section ); add_settings_field( 'serverpush', __( 'HTTP/2 Server Push', 'awpp' ), [ $this, 'serverpush_callback' ], $this->settings_page, $section ); } public function sanitize( $input ) { $new_input = []; $checkboxes = [ 'scripts_to_footer', 'minify' ]; $select = [ 'loadcss', 'serverpush' ]; foreach ( $checkboxes as $key ) { if ( ! isset( $input[ $key ] ) ) { $new_input[ $key ] = 'disabled'; } else { $new_input[ $key ] = $input[ $key ]; } } foreach ( $select as $key ) { if ( ! array_key_exists( $input[ $key ], $this->select_choices[ $key ] ) ) { $new_input[ $key ] = array_keys( $this->select_choices[ $key ] )[0]; } else { $new_input[ $key ] = $input[ $key ]; } } if ( 'htaccess' == $new_input['serverpush'] && isset( $input['serverpush_files'] ) ) { $new_input['serverpush_files'] = $input['serverpush_files']; } if ( 'classic' == $new_input['loadcss'] && isset( $input['criticalcss'] ) ) { $new_input['criticalcss'] = $input['criticalcss']; } /*if ( 'api' == $new_input['loadcss'] ) { add_settings_error( $this->settings_option . 'errors', 'criticalapi-message', 'test', 'updated' ); }*/ return $new_input; } public function update_file( $input ) { if ( apply_filters( 'awpp_critical_dir', awpp_get_instance()->CriticalCSS->default_critical_path ) != awpp_get_instance()->CriticalCSS->default_critical_path ) { return $input; } if ( ! isset( $input['criticalcss'] ) ) { return $input; } $css = $input['criticalcss']; if ( ! isset( $input['criticalcss'] ) ) { return $input; } $path = plugin_dir_path( awpp_get_instance()->file ) . 'Classes/Libs'; require_once $path . '/minify/autoload.php'; require_once $path . '/path-converter/autoload.php'; $minifier = new \MatthiasMullie\Minify\CSS( $css ); $minifier->minify( awpp_get_instance()->CriticalCSS->default_critical_path . 'index.css' ); return $input; } public function print_section_info() { //echo '
';
		//print_r( $this->options );
		//echo '
'; } public function scripts_to_footer_callback() { $key = 'scripts_to_footer'; $val = $this->get_val( $key, 'on' ); printf( '', $this->settings_option, $key, ( 'on' == $val ? 'checked' : '' ) ); } public function minify_callback() { $key = 'minify'; $val = $this->get_val( $key, 'on' ); printf( '', $this->settings_option, $key, ( 'on' == $val ? 'checked' : '' ) ); } public function loadcss_callback() { $key = 'loadcss'; $val = $this->get_val( $key, 'disabled' ); if ( 'on' == $val ) { $val = 'classic'; } echo ''; //return; //$val = $this->get_val( $key, 'on' ); //printf( '', $this->settings_option, $key, ( 'on' == $val ? 'checked' : '' ) ); ?>

CriticalCSS->default_critical_path ); if ( awpp_get_instance()->CriticalCSS->default_critical_path != $path ) { echo '

' . __( 'Custom critical directory found:', 'awpp' ) . ' ' . $path . '

'; if ( ! is_dir( $path ) ) { echo '

' . __( 'Folder does not exist!', 'awpp' ) . '

'; } if ( ! is_file( $path . 'index.css' ) ) { echo '

' . __( 'index.css does not exist!', 'awpp' ) . '

'; } } else { $file = awpp_get_instance()->CriticalCSS->default_critical_path . 'index.css'; if ( ! file_exists( $file ) ) { fopen( $file, 'w' ); } $key = 'criticalcss'; $file_url = str_replace( awpp_get_instance()->CriticalCSS->base_path, awpp_get_instance()->CriticalCSS->base_url, $file ); $val = file_get_contents( $file ); printf( '', $this->settings_option, $key, $val ); echo "

File: $file_url

"; } ?>
get_val( $key, 'disabled' ); echo ''; ?>

Http2Push->serverpush_possfiles_option ); if ( ! is_array( $scanned_files ) || empty( $scanned_files ) ) { $scanned_files = [ 'styles' => [], 'scripts' => [], ]; } foreach ( [ 'styles', 'scripts' ] as $type ) { echo '

' . ucfirst( $type ) . '

'; echo ''; } ?>

$this->adminbar_id, 'title' => str_replace( 'Advanced ', '', awpp_get_instance()->name ), 'href' => admin_url( 'options-general.php?page=' . $this->settings_page ), 'meta' => [ 'class' => awpp_get_instance()->prefix . '-adminbar', ], ]; $wp_admin_bar->add_node( $args ); } public function http2_check() { add_action( 'admin_notices', function () { if ( get_current_screen()->id != 'settings_page_' . $this->settings_page || getenv( 'X_SPDY' ) != '' ) { return; } // translators: To get the maximum out of Advanced WPPerformance you should upgrade to HTTP/2. Currenty your server supports HTTP/1 $message = sprintf( __( 'To get the maximum out of %1$1s you should upgrade to HTTP/2. Currently your server supports %2$2s', 'awpp' ), '' . awpp_get_instance()->name . '', $_SERVER['SERVER_PROTOCOL'] ); printf( '

%s

', $message ); } ); } public function set_default_settings() { $options = $this->options; $defaults = [ 'scripts_to_footer' => 'on', 'minify' => 'on', 'loadcss' => 'disabled', 'serverpush' => 'disabled', ]; foreach ( $defaults as $key => $default ) { if ( ! isset( $options[ $key ] ) ) { $options[ $key ] = $default; } } update_option( $this->settings_option, $options ); } /** * Helpers */ public function get_val( $key, $default = '' ) { if ( isset( $this->options[ $key ] ) ) { return $this->options[ $key ]; } else { return $default; } } }