capability = 'administrator';
$this->prefix = 'awpp';
$this->title = self::$name;
$this->key = $this->prefix . '-' . sanitize_title( self::$name );
}
public function run() {
add_action( 'admin_menu', [ $this, 'register_subpage' ] );
add_action( 'awpp_criticalapi_section', [ $this, 'section_about' ] );
add_action( 'awpp_criticalapi_section', [ $this, 'section_recommended' ] );
add_action( 'awpp_criticalapi_section', [ $this, 'section_posttypes' ] );
add_action( 'awpp_criticalapi_section', [ $this, 'section_taxonomies' ] );
add_action( 'awpp_criticalapi_section', [ $this, 'section_special' ] );
add_action( 'awpp_criticalapi_section', [ $this, 'section_date' ] );
// Singles
add_action( 'add_meta_boxes', [ $this, 'register_meta_box' ] );
foreach ( self::get_taxonomies() as $key => $name ) {
add_action( $key . '_edit_form_fields', [ $this, 'criticalapi_tax_field' ], 10, 2 );
}
add_action( 'show_user_profile', [ $this, 'criticalapi_user_field' ], 10, 1 );
add_action( 'edit_user_profile', [ $this, 'criticalapi_user_field' ], 10, 1 );
}
public function register_subpage() {
if ( '' == awpp_get_setting( self::$apikey_key ) || ! awpp_get_setting( self::$apikey_key ) ) {
return;
}
add_submenu_page( AWPP_SETTINGS_PARENT, $this->title, $this->title, $this->capability, $this->key, [ $this, 'adminpage' ] );
}
public function adminpage() {
?>
';
echo '' . __( 'About critical-css.io', 'awpp' ) . '
';
// translators: critical-css.io is a project by {say hello}.
$description = '' . sprintf( __( 'critical-css.io is a project by %s.', 'awpp' ), 'say hello' ) . '
';
$description .= '' . __( 'The service is based on a powerfull API which returns the CSS required for the first screen of a webpage.', 'awpp' ) . '
';
echo $description;
echo '';
}
public function section_recommended() {
echo '';
echo '
' . __( 'Recommended Pages', 'awpp' ) . '
';
echo '
';
echo '';
echo '| ' . __( 'Element', 'awpp' ) . ' | ';
echo '' . __( 'generated', 'awpp' ) . ' | ';
echo ' | ';
echo '
';
$select_array = array_merge( [
'-' => [
'name' => __( 'Select Page', 'awpp' ),
'url' => '',
],
], self::get_all_critical_elements() );
echo self::render_criticalapi_generate_list( 'index', __( 'Fallback (index.css)', 'awpp' ), $select_array );
echo self::render_criticalapi_generate_list( 'front-page', __( 'Front Page', 'awpp' ), get_home_url() );
echo self::render_criticalapi_generate_list( 'singular', __( 'Singular', 'awpp' ), $select_array );
echo self::render_criticalapi_generate_list( 'archive', __( 'Archive', 'awpp' ), '' );
echo '
';
echo '
';
}
public function section_posttypes() {
echo '';
echo '
' . __( 'Post Types', 'awpp' ) . '
';
echo '
';
echo '';
echo '| ' . __( 'Element', 'awpp' ) . ' | ';
echo '' . __( 'generated', 'awpp' ) . ' | ';
echo ' | ';
echo '
';
$select_array = array_merge( [
'-' => [
'name' => __( 'Select Page', 'awpp' ),
'url' => '',
],
], self::get_all_critical_elements() );
foreach ( self::get_post_types() as $key => $name ) {
echo self::render_criticalapi_generate_list( 'singular-' . $key, $name, $select_array[ 'singular-' . $key ] );
if ( '' != get_post_type_archive_link( $key ) ) {
echo self::render_criticalapi_generate_list( 'archive-' . $key, __( 'Archive', 'awpp' ) . ': ' . $name, get_post_type_archive_link( $key ) );
}
}
echo '
';
echo '
';
}
public function section_taxonomies() {
echo '';
echo '
' . __( 'Taxonomies', 'awpp' ) . '
';
echo '
';
echo '';
echo '| ' . __( 'Element', 'awpp' ) . ' | ';
echo '' . __( 'generated', 'awpp' ) . ' | ';
echo ' | ';
echo '
';
$select_array = array_merge( [
'-' => [
'name' => __( 'Select Page', 'awpp' ),
'url' => '',
],
], self::get_all_critical_elements() );
foreach ( self::get_taxonomies() as $key => $name ) {
echo self::render_criticalapi_generate_list( 'archvie-taxonomy-' . $key, $name, $select_array[ 'archive-taxonomy-' . $key ] );
}
echo '
';
echo '
';
}
public function section_special() {
echo '';
echo '
' . __( 'Special Pages', 'awpp' ) . '
';
echo '
';
echo '';
echo '| ' . __( 'Element', 'awpp' ) . ' | ';
echo '' . __( 'generated', 'awpp' ) . ' | ';
echo ' | ';
echo '
';
$select_array = array_merge( [
'-' => [
'name' => __( 'Select Page', 'awpp' ),
'url' => '',
],
], self::get_all_critical_elements() );
echo self::render_criticalapi_generate_list( 'archive-author', __( 'Archive Author', 'awpp' ), $select_array['archive-author'] );
echo self::render_criticalapi_generate_list( '404', __( '404 Page', 'awpp' ), '' );
echo self::render_criticalapi_generate_list( 'search', __( 'Search Page', 'awpp' ), '' );
echo '
';
echo '
';
}
public function section_date() {
echo '';
echo '
' . __( 'Archive Date', 'awpp' ) . '
';
echo '
';
echo '';
echo '| ' . __( 'Element', 'awpp' ) . ' | ';
echo '' . __( 'generated', 'awpp' ) . ' | ';
echo ' | ';
echo '
';
$select_array = array_merge( [
'-' => [
'name' => __( 'Select Page', 'awpp' ),
'url' => '',
],
], self::get_all_critical_elements() );
echo self::render_criticalapi_generate_list( 'archive-date', __( 'Archive Date', 'awpp' ), '' );
echo self::render_criticalapi_generate_list( 'archive-date-year', '- ' . __( 'Archive Date Year', 'awpp' ), '' );
echo self::render_criticalapi_generate_list( 'archive-date-month', '- ' . __( 'Archive Date Month', 'awpp' ), '' );
echo self::render_criticalapi_generate_list( 'archive-date-day', '- ' . __( 'Archive Date Day', 'awpp' ), '' );
echo '
';
echo '
';
}
/**
*Singles
*/
public function register_meta_box() {
foreach ( self::get_post_types() as $key => $name ) {
add_meta_box( 'criticalapi-meta-box', self::$name, [ $this, 'criticalapi_meta_box' ], $key, 'side', 'low' );
}
}
public function criticalapi_meta_box( $post ) {
if ( 'publish' != $post->post_status ) {
echo '' . __( 'Please publish the post before generating the Critical CSS.', 'awpp' ) . '
';
} else {
echo self::render_criticalapi_generate_single( "singular-{$post->ID}", get_permalink( $post->ID ) );
}
}
public function criticalapi_tax_field( $term ) {
echo '';
echo ' | ';
echo '' . self::render_criticalapi_generate_single( "archvie-taxonomy-{$term->term_id}", get_term_link( $term ) ) . ' | ';
echo '
';
}
public function criticalapi_user_field( $user ) {
echo '';
}
}