diff --git a/archive.php b/archive.php index 67bc0c63..b6c290f0 100644 --- a/archive.php +++ b/archive.php @@ -12,7 +12,10 @@
- +
diff --git a/content.php b/content.php index f481e193..3585d593 100644 --- a/content.php +++ b/content.php @@ -4,4 +4,4 @@ */ the_content(); -?> + diff --git a/functions.php b/functions.php index 8b52ab3b..87a1958f 100644 --- a/functions.php +++ b/functions.php @@ -26,12 +26,12 @@ function get_blog_url( $path = '' ) { /** * Load My Team widget */ -require_once( get_template_directory() . '/widgets/my-team/my-team.php' ); +require_once get_template_directory() . '/widgets/my-team/my-team.php'; /** * Load partner plugins loader file. */ -require_once( 'thirdparty.php' ); +require_once 'thirdparty.php'; /** * Global variable for WP core and various plugins to size embeds/images appropriately. @@ -66,10 +66,10 @@ function social_init() { } // Show buttons everywhere - $sharing_options = get_option( 'sharing-options' ); + $sharing_options = get_option( 'sharing-options' ); $show_in_locations = [ 'index', 'post', 'page', 'attachment' ]; if ( ! is_array( $sharing_options['global']['show'] ) || - count( array_intersect( $sharing_options['global']['show'], $show_in_locations ) ) !== count( $show_in_locations ) ) { + count( array_intersect( $sharing_options['global']['show'], $show_in_locations ) ) !== count( $show_in_locations ) ) { $sharing_options['global']['show'] = $show_in_locations; update_option( 'sharing-options', $sharing_options ); } @@ -101,7 +101,7 @@ function disable_related_posts() { /* * Load Jetpack compatibility file. */ -require( get_template_directory() . '/inc/jetpack.php' ); +require get_template_directory() . '/inc/jetpack.php'; /** * Sets up theme defaults and registers support for various WordPress features. @@ -115,12 +115,12 @@ function setup() { /** * Custom functions that act independently of the theme templates */ - require( get_template_directory() . '/inc/extras.php' ); + require get_template_directory() . '/inc/extras.php'; /** * Customizer additions */ - require( get_template_directory() . '/inc/customizer/customizer.php' ); + require get_template_directory() . '/inc/customizer/customizer.php'; /** * Make theme available for translation @@ -164,18 +164,20 @@ function setup() { /** * This theme uses wp_nav_menu() in one location. */ - register_nav_menus( [ - 'primary' => __( 'Primary Menu', 'p2020' ), - ] ); + register_nav_menus( + [ + 'primary' => __( 'Primary Menu', 'p2020' ), + ] + ); /** * Add a menu with Home item, if location is empty. */ $locations = get_theme_mod( 'nav_menu_locations' ); $menu_link = [ - 'menu-item-title' => __( 'Learn more about P2', 'p2020' ), - 'menu-item-url' => 'https://wordpress.com/p2/', - 'menu-item-status' => 'publish' + 'menu-item-title' => __( 'Learn more about P2', 'p2020' ), + 'menu-item-url' => 'https://wordpress.com/p2/', + 'menu-item-status' => 'publish', ]; if ( empty( $locations['primary'] ) ) { @@ -193,12 +195,12 @@ function setup() { } else { $menu = wp_get_nav_menu_object( 'primary' ); - if( $menu ) { + if ( $menu ) { $menu_items = wp_get_nav_menu_items( $menu ); - if( $menu_items ) { - foreach( $menu_items as $menu_item ) { + if ( $menu_items ) { + foreach ( $menu_items as $menu_item ) { // replace existing Home link with `Learn about P2` - if( $menu_item->post_title === 'Home' && $menu_item->url === '/' ) { + if ( 'Home' === $menu_item->post_title && '/' === $menu_item->url ) { wp_update_nav_menu_item( $menu->term_id, $menu_item->ID, $menu_link ); } } @@ -213,14 +215,16 @@ function setup() { * Register widgetized area */ function widget_areas_init() { - register_sidebar( [ - 'name' => __( 'Primary Sidebar', 'p2020' ), - 'id' => 'sidebar-1', - 'before_widget' => '', - 'before_title' => '

', - 'after_title' => '

', - ] ); + register_sidebar( + [ + 'name' => __( 'Primary Sidebar', 'p2020' ), + 'id' => 'sidebar-1', + 'before_widget' => '', + 'before_title' => '

', + 'after_title' => '

', + ] + ); } add_action( 'widgets_init', __NAMESPACE__ . '\widget_areas_init' ); @@ -234,7 +238,7 @@ function fonts() { * by Inter, translate this to 'off'. Do not translate into your own language. */ if ( 'off' !== _x( 'on', 'Sans: on or off', 'p2020' ) ) { - wp_register_style( 'p2020-sans', "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" ); + wp_register_style( 'p2020-sans', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap', [], '20200801' ); } } @@ -244,7 +248,7 @@ function fonts() { * Enqueue font styles in custom header admin */ function admin_fonts( $hook_suffix ) { - if ( 'appearance_page_custom-header' != $hook_suffix ) { + if ( 'appearance_page_custom-header' !== $hook_suffix ) { return; } @@ -284,7 +288,7 @@ function maybe_remove_contributor_role() { * Enqueue scripts and styles */ function scripts() { - wp_enqueue_style( 'p2020-style', get_stylesheet_uri() ); + wp_enqueue_style( 'p2020-style', get_stylesheet_uri(), [], '20200801' ); wp_style_add_data( 'p2020-style', 'rtl', 'replace' ); wp_enqueue_style( 'p2020-sans' ); @@ -293,17 +297,23 @@ function scripts() { wp_enqueue_script( 'p2020-debounce', get_template_directory_uri() . '/js/vendor/jquery.ba-throttle-debounce.min.js', [], '20200416', true ); // Main enqueued file - wp_enqueue_script( 'p2020-js', get_template_directory_uri() . '/js/enqueued-main.js', [ - 'o2-enquire', - 'p2020-modernizr' - ], '20200416', true ); + wp_enqueue_script( + 'p2020-js', + get_template_directory_uri() . '/js/enqueued-main.js', + [ + 'o2-enquire', + 'p2020-modernizr', + ], + '20200416', + true + ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } if ( is_singular() && wp_attachment_is_image() ) { - wp_enqueue_script( 'p2020-keyboard-image-navigation', get_template_directory_uri() . '/js/vendor/keyboard-image-navigation.js', [ 'jquery' ], '20120202' ); + wp_enqueue_script( 'p2020-keyboard-image-navigation', get_template_directory_uri() . '/js/vendor/keyboard-image-navigation.js', [ 'jquery' ], '20120202', true ); } } @@ -313,18 +323,24 @@ function scripts() { function admin_styles() { wp_enqueue_style( 'p2020-admin-common-style', - get_stylesheet_directory_uri() . '/admin-common-style.css' + get_stylesheet_directory_uri() . '/admin-common-style.css', + [], + '20200801' ); if ( is_a8c_p2() ) { wp_enqueue_style( 'p2020-admin-a8c-p2-style', - get_stylesheet_directory_uri() . '/admin-a8c-p2-style.css' + get_stylesheet_directory_uri() . '/admin-a8c-p2-style.css', + [], + '20200801' ); } else { wp_enqueue_style( 'p2020-admin-non-a8c-p2-style', - get_stylesheet_directory_uri() . '/admin-non-a8c-p2-style.css' + get_stylesheet_directory_uri() . '/admin-non-a8c-p2-style.css', + [], + '20200801' ); } } @@ -338,7 +354,7 @@ function editor_assets() { // Main editor enqueued file wp_enqueue_script( 'p2020-editor-js', get_template_directory_uri() . '/js/enqueued-editor-main.js', [], '20200430', true ); - $blocksBlacklist = [ + $blocks_blacklist = [ 'jetpack/calendly', 'jetpack/opentable', 'jetpack/recurring-payments', @@ -350,31 +366,34 @@ function editor_assets() { ]; if ( ! is_a8c_p2() ) { - $blocksBlacklist = array_merge( $blocksBlacklist, [ - 'core/video', - 'jetpack/eventbrite', - 'jetpack/map', - 'jetpack/timeline', - 'jetpack/event-countdown', - 'jetpack/layout-grid', - 'jetpack/layout-grid-column', - 'jetpack/mailchimp', - 'jetpack/revue', - 'core-embed/videopress', - 'core-embed/facebook', - 'core-embed/imgur', - 'core-embed/kickstarter', - 'core-embed/hulu', - 'core-embed/crowdsignal', - 'core/file', - 'a8c/posts-carousel', - 'premium-content/buttons', - 'premium-content/login-button', - ] ); + $blocks_blacklist = array_merge( + $blocks_blacklist, + [ + 'core/video', + 'jetpack/eventbrite', + 'jetpack/map', + 'jetpack/timeline', + 'jetpack/event-countdown', + 'jetpack/layout-grid', + 'jetpack/layout-grid-column', + 'jetpack/mailchimp', + 'jetpack/revue', + 'core-embed/videopress', + 'core-embed/facebook', + 'core-embed/imgur', + 'core-embed/kickstarter', + 'core-embed/hulu', + 'core-embed/crowdsignal', + 'core/file', + 'a8c/posts-carousel', + 'premium-content/buttons', + 'premium-content/login-button', + ] + ); } $data = [ - 'blocksBlacklist' => $blocksBlacklist, + 'blocksBlacklist' => $blocks_blacklist, ]; wp_localize_script( 'p2020-editor-js', 'p2020Editor', $data ); @@ -387,7 +406,7 @@ function editor_assets() { */ function set_homepage_display() { $show_on_front = get_option( 'show_on_front' ); - if ( $show_on_front !== 'posts' ) { + if ( 'posts' !== $show_on_front ) { update_option( 'show_on_front', 'posts' ); } } @@ -405,7 +424,7 @@ function enable_default_widgets() { return; } - if ( $setup_option === 'reset' ) { + if ( 'reset' === $setup_option ) { $sidebars_widgets = []; } else { $sidebars_widgets = get_option( 'sidebars_widgets' ); @@ -414,12 +433,12 @@ function enable_default_widgets() { // My Team widget (widgets/myteam) $widget_instance = "p2020-my-team-widget-{$widget_no}"; - if ( empty( $sidebars_widgets['sidebar-1'] ) || ! in_array( $widget_instance, $sidebars_widgets['sidebar-1'] ) ) { + if ( empty( $sidebars_widgets['sidebar-1'] ) || ! in_array( $widget_instance, $sidebars_widgets['sidebar-1'], true ) ) { $team_widget_settings = [ $widget_no => [ 'title' => __( 'Team', 'p2020' ), 'limit' => 14, - ] + ], ]; update_option( 'widget_p2020-my-team-widget', $team_widget_settings ); @@ -428,15 +447,10 @@ function enable_default_widgets() { } // Save sidebar updates - $sidebars_widgets['array_version'] = 3; - update_option( 'sidebars_widgets', $sidebars_widgets ); + wp_set_sidebars_widgets( $sidebars_widgets ); // Clear sidebar setup flag afterwards update_option( 'p2020_sidebar_setup', false ); - - // Refresh sidebars_widgets cache - global $_wp_sidebars_widgets; - $_wp_sidebars_widgets = $sidebars_widgets; } add_action( 'after_setup_theme', __NAMESPACE__ . '\enable_default_widgets' ); @@ -460,8 +474,9 @@ function hide_o2_editor( $o2_options ) { * Replace UI strings in O2 */ function replace_o2_strings( array $o2_options ): array { - $o2_options['strings']['noPosts'] = __( 'Ready to publish your first post? Simply use the editor above.', 'p2020' ); - $o2_options['strings']['noPostsMobile'] = __( 'Tap the + button in the top right corner to begin writing your first post.', 'p2020' );; + $o2_options['strings']['noPosts'] = __( 'Ready to publish your first post? Simply use the editor above.', 'p2020' ); + $o2_options['strings']['noPostsMobile'] = __( 'Tap the + button in the top right corner to begin writing your first post.', 'p2020' ); + return $o2_options; } @@ -475,7 +490,7 @@ function config_p2tenberg_comment_editor( array $settings ): array { return $settings; } -add_filter ( 'p2tenberg_comment_editor', __NAMESPACE__ . '\config_p2tenberg_comment_editor' ); +add_filter( 'p2tenberg_comment_editor', __NAMESPACE__ . '\config_p2tenberg_comment_editor' ); /** * Append Contributor block to content on single pages @@ -485,7 +500,7 @@ function append_contributors_block( $content ) { return $content; } - require_once( get_template_directory() . '/inc/contributors.php' ); + require_once get_template_directory() . '/inc/contributors.php'; return $content . get_contributors_block(); } @@ -519,7 +534,7 @@ function customizer_widgets_styles( $hook ) { return; } - wp_enqueue_style( 'p2020-customizer-widgets', get_template_directory_uri() . '/widgets/customizer.css' ); + wp_enqueue_style( 'p2020-customizer-widgets', get_template_directory_uri() . '/widgets/customizer.css', [], '20200801' ); } add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\customizer_widgets_styles' ); @@ -527,29 +542,29 @@ function customizer_widgets_styles( $hook ) { /** * Filter: enqueue scripts, hook actions and filters. */ - function p2020_filter_init() { - require_once( get_template_directory() . '/inc/filter/filter.php' ); +function p2020_filter_init() { + require_once get_template_directory() . '/inc/filter/filter.php'; \P2020\Filter\enqueue_scripts(); \P2020\Filter\add_hooks(); - } +} - add_action( 'after_setup_theme', __NAMESPACE__ . '\p2020_filter_init' ); +add_action( 'after_setup_theme', __NAMESPACE__ . '\p2020_filter_init' ); /** * Follow: enqueue scripts */ function p2020_follow_init() { - require_once( get_template_directory() . '/inc/follow/follow.php' ); + require_once get_template_directory() . '/inc/follow/follow.php'; \P2020\Follow\enqueue_scripts(); } -add_action ( 'after_setup_theme', __NAMESPACE__ . '\p2020_follow_init' ); +add_action( 'after_setup_theme', __NAMESPACE__ . '\p2020_follow_init' ); /** * Menu: enqueue scripts, hook actions and filters. */ function p2020_menu_init() { - require_once( get_template_directory() . '/inc/menu/menu.php' ); + require_once get_template_directory() . '/inc/menu/menu.php'; \P2020\Menu\enqueue_scripts(); } diff --git a/header.php b/header.php index 38ac062b..35312a43 100644 --- a/header.php +++ b/header.php @@ -16,14 +16,11 @@ - + <?php wp_title( '–', true, 'right' ); ?> - items[] = [ 'label' => $label, - 'url' => $url, + 'url' => $url, ]; } private function make_list(): string { - $list_items = array_map( function ( array $item ): string { - $label = esc_html( $item['label'] ); - $url = esc_url( $item['url'] ); + $list_items = array_map( + function ( array $item ): string { + $label = esc_html( $item['label'] ); + $url = esc_url( $item['url'] ); - return << $label ITEM; - }, $this->items ); + }, + $this->items + ); return ''; } @@ -47,7 +50,7 @@ private function make_list(): string { * Returns the HTML for the menu. */ public function generate(): string { - $list = $this->make_list(); + $list = $this->make_list(); $menu_label = esc_attr__( 'More', 'p2020' ); // Outer div is required for proper tab order @@ -66,7 +69,5 @@ class="p2020-ellipsis-button" MENU; - - return $list; } } diff --git a/inc/contributors.php b/inc/contributors.php index 7d2198be..d8b0a4d3 100644 --- a/inc/contributors.php +++ b/inc/contributors.php @@ -8,8 +8,8 @@ namespace P2020; function get_contributors( int $post_author, int $limit = 3 ): array { - $args = [ 'order' => 'ASC' ]; - $revisions = wp_get_post_revisions( get_queried_object_id(), $args ); + $args = [ 'order' => 'ASC' ]; + $revisions = wp_get_post_revisions( get_queried_object_id(), $args ); $authors_by_contribution_count = [ $post_author => 1 ]; foreach ( (array) $revisions as $revision ) { @@ -25,33 +25,34 @@ function get_contributors( int $post_author, int $limit = 3 ): array { } function get_contributors_block(): string { - $post_author = get_post()->post_author; + $post_author = get_post()->post_author; $contributors = get_contributors( $post_author ); if ( count( $contributors ) === 0 ) { return null; } - $contributor_list_items = array_map( function ( int $contributor_id, int $count ): string { - $userdata = get_userdata( $contributor_id ); - $avatar = get_avatar( $contributor_id, 36 ); - $link = esc_url( get_author_posts_url( $contributor_id ) ); - $link_title = esc_attr( - sprintf( + $contributor_list_items = array_map( + function ( int $contributor_id, int $count ): string { + $userdata = get_userdata( $contributor_id ); + $avatar = get_avatar( $contributor_id, 36 ); + $link = esc_url( get_author_posts_url( $contributor_id ) ); + $link_title = esc_attr( + sprintf( /* translators: %1$s is replaced with the user's display name; %2$s is the user's nicename */ - __( 'Posts by %1$s ( @%2$s )', 'p2020' ), - $userdata->display_name, - $userdata->user_nicename - ) - ); - $name = esc_html( $userdata->display_name ); + __( 'Posts by %1$s ( @%2$s )', 'p2020' ), + $userdata->display_name, + $userdata->user_nicename + ) + ); + $name = esc_html( $userdata->display_name ); - $revisions = esc_html( + $revisions = esc_html( /* translators: %s is replaced with the number of revisions */ - sprintf( _n( '%s revision', '%s revisions', $count, 'p2020' ), $count ) - ); + sprintf( _n( '%s revision', '%s revisions', $count, 'p2020' ), $count ) + ); - return <<
$avatar @@ -70,7 +71,10 @@ class="p2020-contributors__item-name"
LISTITEM; - }, array_keys( $contributors ), $contributors ); + }, + array_keys( $contributors ), + $contributors + ); $contributor_list_items_imploded = implode( '', $contributor_list_items ); diff --git a/inc/customizer/custom-colors.php b/inc/customizer/custom-colors.php index 3a7df7d5..1325ef53 100644 --- a/inc/customizer/custom-colors.php +++ b/inc/customizer/custom-colors.php @@ -7,47 +7,56 @@ namespace P2020; -require( get_template_directory() . '/inc/vendor/Color.php' ); +require get_template_directory() . '/inc/vendor/Color.php'; use Mexitek\PHPColors\Color as Color; // Keep in sync with CSS variables/themes function get_default_color( string $key ): string { $default_colors = [ - 'color_link' => '#0267ff', - 'color_mentions' => '#b35eb1', + 'color_link' => '#0267ff', + 'color_mentions' => '#b35eb1', 'color_sidebar_background' => '#f3f3f3', - 'color_sidebar_content' => '#00101c', + 'color_sidebar_content' => '#00101c', ]; - return $default_colors[$key]; + return $default_colors[ $key ]; } // Whether a color option is set and is a non-default value -function isCustomColor( array $options, string $key ): bool { +function is_custom_color( array $options, string $key ): bool { if ( ! isset( $options[ $key ] ) ) { return false; } $color = $options[ $key ]; - return $color !== get_default_color( $key ); + return get_default_color( $key ) !== $color; } function color_hex_to_rgba( string $hex, float $alpha ): string { - $rgb = sscanf( $hex, '#%02x%02x%02x' ); + $rgb = sscanf( $hex, '#%02x%02x%02x' ); $rgb[] = $alpha; return sprintf( 'rgba(%d, %d, %d, %f);', ...$rgb ); } // Utility function to add a single color setting and control function register_color( \WP_Dotcom_Customize $wp_customize, string $key, string $label ) { - $wp_customize->add_setting( "p2020_theme_options[$key]", [ - 'default' => get_default_color( $key ), - 'sanitize_callback' => 'sanitize_hex_color', - ] ); - $wp_customize->add_control( new \WP_Customize_Color_Control( $wp_customize, $key, [ - 'label' => $label, - 'section' => 'colors', - 'settings' => "p2020_theme_options[$key]", - ] ) ); + $wp_customize->add_setting( + "p2020_theme_options[$key]", + [ + 'default' => get_default_color( $key ), + 'sanitize_callback' => 'sanitize_hex_color', + ] + ); + $wp_customize->add_control( + new \WP_Customize_Color_Control( + $wp_customize, + $key, + [ + 'label' => $label, + 'section' => 'colors', + 'settings' => "p2020_theme_options[$key]", + ] + ) + ); } /** @@ -75,35 +84,35 @@ function color_styles() { if ( ! $options ) { return; } -?> + ?> - '000', - 'width' => 304 * 2, /* 2x resolution */ - 'height' => 152 * 2, /* 2x resolution */ - 'flex-width' => true, - 'flex-height' => true, - 'header-text' => false, + 'width' => 304 * 2, /* 2x resolution */ + 'height' => 152 * 2, /* 2x resolution */ + 'flex-width' => true, + 'flex-height' => true, + 'header-text' => false, ]; -add_theme_support( 'custom-header', $args ); +add_theme_support( 'custom-header', $args ); diff --git a/inc/customizer/customizer.php b/inc/customizer/customizer.php index d7d2f6da..9a90a17e 100644 --- a/inc/customizer/customizer.php +++ b/inc/customizer/customizer.php @@ -7,8 +7,8 @@ namespace P2020; -require( get_template_directory() . '/inc/customizer/custom-header.php' ); -require( get_template_directory() . '/inc/customizer/custom-colors.php' ); +require get_template_directory() . '/inc/customizer/custom-header.php'; +require get_template_directory() . '/inc/customizer/custom-colors.php'; /** * Add postMessage support for site title and description for the Theme Customizer. @@ -16,33 +16,36 @@ * @param WP_Dotcom_Customize $wp_customize Theme Customizer object. */ function customize_register( \WP_Dotcom_Customize $wp_customize ) { - $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; - $wp_customize->selective_refresh->add_partial( 'header_image', [ - 'selector' => '#p2020-custom-header-partial', - ] ); + $wp_customize->selective_refresh->add_partial( + 'header_image', + [ + 'selector' => '#p2020-custom-header-partial', + ] + ); /** * Add P2 Identity section with site title, tagline and header image controls. */ // Rename Site Identity section to Name and description - $wp_customize->get_section( 'title_tagline' )->title = __( 'Name and description', 'p2020' ); + $wp_customize->get_section( 'title_tagline' )->title = __( 'Name and description', 'p2020' ); $wp_customize->get_section( 'title_tagline' )->priority = 1; // Site Title $wp_customize->get_control( 'blogname' )->priority = 1; // Rename Tagline to Description and convert to textarea type - $wp_customize->get_control( 'blogdescription' )->label = __( 'Description', 'p2020' ); - $wp_customize->get_control( 'blogdescription' )->type = 'textarea'; + $wp_customize->get_control( 'blogdescription' )->label = __( 'Description', 'p2020' ); + $wp_customize->get_control( 'blogdescription' )->type = 'textarea'; $wp_customize->get_control( 'blogdescription' )->priority = 2; // Site Icon $wp_customize->get_control( 'site_icon' )->priority = 3; // Move Header Image section to after Name and description - $wp_customize->get_section( 'header_image' )->title = __( 'Header image', 'p2020' ); + $wp_customize->get_section( 'header_image' )->title = __( 'Header image', 'p2020' ); $wp_customize->get_section( 'header_image' )->priority = 2; } diff --git a/inc/extras.php b/inc/extras.php index 7135569e..31fed63b 100644 --- a/inc/extras.php +++ b/inc/extras.php @@ -8,15 +8,6 @@ */ namespace P2020; -/** - * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link. - */ -function page_menu_args( $args ) { - $args['show_home'] = true; - return $args; -} - -//add_filter( 'wp_page_menu_args', 'P2020\page_menu_args' ); /** * Adds custom classes to the array of body classes. @@ -30,7 +21,7 @@ function body_classes( array $classes ): array { $classes[] = 'group-blog'; } - if( has_nav_menu( 'primary' ) ){ + if ( has_nav_menu( 'primary' ) ) { $classes[] = 'custom-menu'; } @@ -46,12 +37,14 @@ function body_classes( array $classes ): array { * Filter in a link to a content ID attribute for the next/previous image links on image attachment pages */ function enhanced_image_navigation( $url, $id ) { - if ( ! is_attachment() && ! wp_attachment_is_image( $id ) ) + if ( ! is_attachment() && ! wp_attachment_is_image( $id ) ) { return $url; + } $image = get_post( $id ); - if ( ! empty( $image->post_parent ) && $image->post_parent != $id ) + if ( ! empty( $image->post_parent ) && (int) $image->post_parent !== (int) $id ) { $url .= '#main'; + } return $url; } @@ -63,16 +56,18 @@ function enhanced_image_navigation( $url, $id ) { function wp_title( string $title, string $sep ): string { global $page, $paged; - if ( is_feed() ) + if ( is_feed() ) { return $title; + } // Add the blog name $title .= get_bloginfo( 'name' ); // Add a page number if necessary: - if ( $paged >= 2 || $page >= 2 ) + if ( $paged >= 2 || $page >= 2 ) { /* translators: %s is replaced with the page number */ $title .= " $sep " . sprintf( __( 'Page %s', 'p2020' ), max( $paged, $page ) ); + } return $title; } @@ -100,10 +95,10 @@ function html_output( string $str ): string { /** * Hide intralink for P2 Pages */ -function p2_show_intralinks( $a, $b ) { +function p2_show_intralinks() { if ( is_page() ) { return false; } return true; } -add_filter( 'a8c_show_intralinks', 'P2020\p2_show_intralinks', 10, 2 ); +add_filter( 'a8c_show_intralinks', 'P2020\p2_show_intralinks' ); diff --git a/inc/filter/filter.php b/inc/filter/filter.php index 0aa51873..145d7574 100644 --- a/inc/filter/filter.php +++ b/inc/filter/filter.php @@ -4,12 +4,12 @@ use function P2020\get_blog_url; -require_once( get_template_directory() . '/inc/filter/unread.php' ); +require_once get_template_directory() . '/inc/filter/unread.php'; require_lib( 'seen-posts' ); -const QUERY_ROWS_LIMIT = 100; +const QUERY_ROWS_LIMIT = 100; const UNREAD_COUNT_DISPLAY_LIMIT = 99; // displays "99+" if unread is > 99 -const DAY_IN_SECONDS = 60 * 60 * 24; +const DAY_IN_SECONDS = 60 * 60 * 24; /** * Checks whether the current page is a 'filter page'. @@ -22,20 +22,24 @@ function is_filter_active( string $type ): bool { global $wp; $user = wp_get_current_user(); + if ( isset( $_GET['nonce'] ) ) { + $nonce_check = wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'p2-filter' ); + } + switch ( $type ) { case 'posts': - return (bool)get_query_var( 'p2filter_posts' ); + return (bool) get_query_var( 'p2filter_posts' ); case 'comments': - return (bool)get_query_var( 'p2filter_comments' ); + return (bool) get_query_var( 'p2filter_comments' ); case 'mentions': - return ( strpos( $wp->request, 'mentions/' . $user->user_nicename ) === 0 ) || - isset( $_GET['mentions'] ); + return ( ( strpos( $wp->request, 'mentions/' . $user->user_nicename ) === 0 ) + || isset( $_GET['mentions'] ) && $nonce_check ); case 'myposts': - return ( strpos( $wp->request, 'author/' . $user->user_nicename ) === 0 ); + return ( strpos( $wp->request, 'author/' . $user->user_nicename ) === 0 ) && $nonce_check; case 'unresolved': - return isset( $_GET['resolved'] ) && $_GET['resolved'] === 'unresolved'; + return isset( $_GET['resolved'] ) && 'unresolved' === $_GET['resolved'] && $nonce_check; case 'resolved': - return isset( $_GET['resolved'] ) && $_GET['resolved'] === 'resolved'; + return isset( $_GET['resolved'] ) && 'resolved' === $_GET['resolved'] && $nonce_check; } return false; @@ -62,65 +66,88 @@ function get_active_filter() { * * @return array An array of filter link items. */ -function get_links() { +function get_filters() { if ( ! is_user_logged_in() ) { return []; } - $user = wp_get_current_user(); + $user = wp_get_current_user(); $last_active = \P2020\Filter\Unread\get_last_active(); - $filters = [ - 'posts' => [ - 'label' => __( 'New posts', 'p2020' ), - 'url' => esc_url( add_query_arg( - [ - 'p2filter_posts' => true, - 'ts' => $last_active['posts'], - ], - get_blog_url() - ) ), - 'class' => 'p2020-filter__recent-updates', + $nonce = wp_create_nonce( 'p2-filter' ); + $filters = [ + 'posts' => [ + 'label' => __( 'New posts', 'p2020' ), + 'url' => esc_url( + add_query_arg( + [ + 'p2filter_posts' => true, + 'ts' => $last_active['posts'], + ], + get_blog_url() + ) + ), + 'class' => 'p2020-filter__recent-updates', 'read_count_enabled' => true, ], 'comments' => [ - 'label' => __( 'New comments', 'p2020' ), - 'url' => esc_url( add_query_arg( - [ - 'p2filter_comments' => true, - 'ts' => $last_active['comments'], - ], - get_blog_url() - ) ), - 'class' => 'p2020-filter__recent-comments', + 'label' => __( 'New comments', 'p2020' ), + 'url' => esc_url( + add_query_arg( + [ + 'p2filter_comments' => true, + 'ts' => $last_active['comments'], + ], + get_blog_url() + ) + ), + 'class' => 'p2020-filter__recent-comments', 'read_count_enabled' => true, ], 'mentions' => [ - 'label' => __( 'My mentions ', 'p2020' ), - 'url' => esc_url( add_query_arg( - [ - 'mentions' => $user->user_nicename, - 'ts' => $last_active['mentions'], - ], - get_blog_url() - ) ), - 'class' => 'p2020-filter__mentions', + 'label' => __( 'My mentions ', 'p2020' ), + 'url' => esc_url( + add_query_arg( + [ + 'mentions' => $user->user_nicename, + 'ts' => $last_active['mentions'], + 'nonce' => $nonce, + ], + get_blog_url() + ) + ), + 'class' => 'p2020-filter__mentions', 'read_count_enabled' => true, ], - 'myposts' => [ - 'label' => __( 'My posts', 'p2020' ), - 'url' => esc_url( get_blog_url( '/author/' . $user->user_nicename ) ), - 'class' => 'p2020-filter__my-posts', + 'myposts' => [ + 'label' => __( 'My posts', 'p2020' ), + 'url' => esc_url( + add_query_arg( + [ + 'nonce' => $nonce, + ], + get_blog_url( '/author/' . $user->user_nicename ) + ) + ), + 'class' => 'p2020-filter__my-posts', 'read_count_enabled' => false, ], ]; - $o2_options = get_option( 'o2_options' ); - $is_resolved_posts_active = ! empty ( $o2_options['enable_resolved_posts'] ); + $o2_options = get_option( 'o2_options' ); + $is_resolved_posts_active = ! empty( $o2_options['enable_resolved_posts'] ); if ( is_automattic() && $is_resolved_posts_active ) { $filters['unresolved'] = [ - 'label' => __( 'To do', 'p2020' ), - 'url' => esc_url( add_query_arg( 'resolved', 'unresolved', get_blog_url() ) ), - 'class' => 'p2020-filter__unresolved-posts', + 'label' => __( 'To do', 'p2020' ), + 'url' => esc_url( + add_query_arg( + [ + 'resolved' => 'unresolved', + 'nonce' => $nonce, + ], + get_blog_url() + ) + ), + 'class' => 'p2020-filter__unresolved-posts', 'read_count_enabled' => false, ]; } @@ -141,15 +168,15 @@ function get_unread_count_display( $count ) { return UNREAD_COUNT_DISPLAY_LIMIT . '+'; } - if ( $count === 0 ) { + if ( 0 === $count ) { return ''; } return $count; } -function render_link_item( $key, $item ) { - $unread_count = \P2020\Filter\Unread\get_unread_count( $key, $limit = UNREAD_COUNT_DISPLAY_LIMIT + 1 ); +function render_filter_item( $key, $item ) { + $unread_count = \P2020\Filter\Unread\get_unread_count( $key, UNREAD_COUNT_DISPLAY_LIMIT + 1 ); $unread_count_display = get_unread_count_display( $unread_count ); $unread_class = get_unread_class( $item, $unread_count ); @@ -168,12 +195,12 @@ function render_link_item( $key, $item ) { } function render() { - $links = get_links(); + $filters = get_filters(); echo ''; } @@ -210,20 +237,20 @@ function add_hooks() { } function scripts() { - if ( is_filter_active( 'posts' ) || is_filter_active( 'comments' ) ) { - wp_enqueue_script( 'p2020-filter-no-posts', get_template_directory_uri() . '/inc/filter/js/no-posts.js', [ 'jquery' ], false, true ); + if ( is_filter_active( 'posts' ) || is_filter_active( 'comments' ) ) { + wp_enqueue_script( 'p2020-filter-no-posts', get_template_directory_uri() . '/inc/filter/js/no-posts.js', [ 'jquery' ], '20200801', true ); $data = [ - 'homeUrl' => esc_url( get_blog_url() ), + 'homeUrl' => esc_url( get_blog_url() ), 'homeMessage' => __( 'Return to home', 'p2020' ), ]; wp_localize_script( 'p2020-filter-no-posts', 'p2020FilterNoPosts', $data ); } if ( is_filter_active( 'comments' ) ) { - wp_enqueue_script( 'p2020-filter-read-more', get_template_directory_uri() . '/inc/filter/js/read-more.js', [ 'jquery' ], false, true ); + wp_enqueue_script( 'p2020-filter-read-more', get_template_directory_uri() . '/inc/filter/js/read-more.js', [ 'jquery' ], '20200801', true ); $data = [ - 'readPost' => __( 'Read full post', 'p2020' ), - 'readComment' => __( 'Read more', 'p2020' ), + 'readPost' => __( 'Read full post', 'p2020' ), + 'readComment' => __( 'Read more', 'p2020' ), 'moreComments' => __( ' more comment(s)', 'p2020' ), ]; wp_localize_script( 'p2020-filter-read-more', 'p2020FilterReadMore', $data ); @@ -245,13 +272,15 @@ function alter_query_for_filter_views( $query ) { } if ( is_filter_active( 'posts' ) ) { - if( is_automattician() ) { + if ( is_automattician() ) { // Use new seen system for a12s // posts after user subscription joined / feature release date $user_subscription_timestamp = \P2020\Filter\Unread\get_user_subscription_timestamp(); if ( $user_subscription_timestamp ) { - $query->set( 'date_query', [ - 'after' => date( 'Y-m-d H:i:s e', $user_subscription_timestamp ), + $query->set( + 'date_query', + [ + 'after' => gmdate( 'Y-m-d H:i:s e', $user_subscription_timestamp ), 'inclusive' => true, ] ); @@ -259,19 +288,21 @@ function alter_query_for_filter_views( $query ) { // post id not in seen $unseen_posts_ids = \P2020\Filter\Unread\get_unseen_blog_posts( $user_subscription_timestamp ); - if( ! empty( $unseen_posts_ids ) ) { + if ( ! empty( $unseen_posts_ids ) ) { $query->set( 'post__in', $unseen_posts_ids ); } - } else { // use old high watermark for non a12s (to be removed) $query->set( 'author', -1 * get_current_user_id() ); $posts_cutoff = \P2020\Filter\Unread\get_content_cutoff_ts( 'posts' ); - if ( ! empty ( $posts_cutoff ) ) { - $query->set( 'date_query', [ - 'after' => date( 'Y-m-d H:i:s e', \P2020\Filter\Unread\get_content_cutoff_ts( 'posts' ) ), - 'inclusive' => true, - ] ); + if ( ! empty( $posts_cutoff ) ) { + $query->set( + 'date_query', + [ + 'after' => gmdate( 'Y-m-d H:i:s e', \P2020\Filter\Unread\get_content_cutoff_ts( 'posts' ) ), + 'inclusive' => true, + ] + ); } } } @@ -295,7 +326,7 @@ function alter_query_for_comment_view( $clauses, $wp_query ) { if ( is_filter_active( 'comments' ) ) { // "SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; $clauses['fields'] = "$wpdb->posts.*, MAX($wpdb->comments.comment_date_gmt) cdate"; - $clauses['join'] = "RIGHT JOIN $wpdb->comments ON (ID = comment_post_id)"; + $clauses['join'] = "RIGHT JOIN $wpdb->comments ON (ID = comment_post_id)"; // Exclude xposts from recent comments queries $clauses['where'] = "AND ( $wpdb->posts.post_title NOT LIKE 'x-post%' AND $wpdb->posts.post_content NOT LIKE 'x-post%' AND $wpdb->posts.post_content NOT LIKE 'x-comment%' )" . @@ -307,8 +338,8 @@ function alter_query_for_comment_view( $clauses, $wp_query ) { $clauses['where'] .= " AND $wpdb->comments.comment_date_gmt >= FROM_UNIXTIME({$comments_cutoff})"; } - $clauses['groupby'] = "ID"; - $clauses['orderby'] = "cdate DESC"; + $clauses['groupby'] = 'ID'; + $clauses['orderby'] = 'cdate DESC'; } return $clauses; @@ -318,6 +349,9 @@ function alter_query_for_comment_view( $clauses, $wp_query ) { * Callback for 'post_class' filter hook. * Add special CSS classes for unread posts, and posts with unread comments and mentions. */ +// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable +// phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed +// Reason: $class unused but passed by filter function custom_classes_for_posts( $classes, $class, $post_id ) { // If a post appears in the recent posts filter view, automatically add "unread" class if ( is_filter_active( 'posts' ) ) { @@ -337,25 +371,29 @@ function custom_classes_for_posts( $classes, $class, $post_id ) { if ( is_filter_active( 'mentions' ) ) { $mentions_cutoff = \P2020\Filter\Unread\get_content_cutoff_ts( 'mentions' ); $unread_mentions = \P2020\Filter\Unread\get_mentions_after_ts( $mentions_cutoff, QUERY_ROWS_LIMIT ); - if ( is_array( $unread_mentions['posts'] ) && in_array( $post_id, $unread_mentions['posts'] ) ) { + if ( is_array( $unread_mentions['posts'] ) && in_array( $post_id, $unread_mentions['posts'], true ) ) { $classes[] = 'p2020-unread-mention'; } } return $classes; } +// phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable +// phpcs:enable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed /** * Callback for 'comment_class' filter hook. * Add special CSS classes for unread comments and comments with unread mentions. */ - +// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable +// phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed +// Reason: $class unused but passed by filter function custom_classes_for_comments( $classes, $class, $comment_id ) { // Flag unread comments, trim everything else if ( is_filter_active( 'comments' ) ) { $comments_cutoff = \P2020\Filter\Unread\get_content_cutoff_ts( 'comments' ); $unread_comments = \P2020\Filter\Unread\get_comments_after_ts( $comments_cutoff, QUERY_ROWS_LIMIT ); - if ( is_array( $unread_comments ) && in_array( $comment_id, $unread_comments ) ) { + if ( is_array( $unread_comments ) && in_array( $comment_id, $unread_comments, true ) ) { $classes[] = 'p2020-unread-comment'; } else { $classes[] = 'p2020-comment-read-more'; @@ -366,23 +404,25 @@ function custom_classes_for_comments( $classes, $class, $comment_id ) { if ( is_filter_active( 'mentions' ) ) { $mentions_cutoff = \P2020\Filter\Unread\get_content_cutoff_ts( 'mentions' ); $unread_mentions = \P2020\Filter\Unread\get_mentions_after_ts( $mentions_cutoff, QUERY_ROWS_LIMIT ); - if ( is_array( $unread_mentions['comments'] ) && in_array( $comment_id, $unread_mentions['comments'] ) ) { + if ( is_array( $unread_mentions['comments'] ) && in_array( $comment_id, $unread_mentions['comments'], true ) ) { $classes[] = 'p2020-unread-mention'; } } return $classes; } +// phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable +// phpcs:enable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed /** * Callback for 'o2_options' filter hook. * Modify the empty page message. */ function no_posts_message( $o2_options ) { - if ( is_filter_active( 'posts' ) || is_filter_active( 'comments' ) ) { - $noPostsMessage = __( "You’re all caught up!", 'p2020' ); - $o2_options['strings']['noPosts'] = $noPostsMessage; - $o2_options['strings']['noPostsMobile'] = $noPostsMessage; + if ( is_filter_active( 'posts' ) || is_filter_active( 'comments' ) ) { + $no_posts_message = __( 'You’re all caught up!', 'p2020' ); + $o2_options['strings']['noPosts'] = $no_posts_message; + $o2_options['strings']['noPostsMobile'] = $no_posts_message; } return $o2_options; @@ -426,27 +466,27 @@ function o2_page_title( $title ) { global $wp_query; - if ( $active_filter === 'unresolved' ) { + if ( 'unresolved' === $active_filter ) { /* translators: %d is the number of posts marked as "To Do" */ return sprintf( __( 'To do (%d)', 'p2020' ), $wp_query->found_posts ); } - if ( $active_filter === 'resolved' ) { + if ( 'resolved' === $active_filter ) { /* translators: %d is the number of posts marked as "To Do" */ return sprintf( __( 'Done (%d)', 'p2020' ), $wp_query->found_posts ); } - if ( $active_filter === 'posts' && $wp_query->found_posts === 0 ) { + if ( 'posts' === $active_filter && 0 === $wp_query->found_posts ) { return ''; } - if ( $active_filter === 'comments' && $wp_query->found_posts === 0 ) { + if ( 'comments' === $active_filter && 0 === $wp_query->found_posts ) { return ''; } - $links = get_links(); - if ( ! empty( $links[ $active_filter ]['label'] ) ) { - return $links[ $active_filter ]['label']; + $filters = get_filters(); + if ( ! empty( $filters[ $active_filter ]['label'] ) ) { + return $filters[ $active_filter ]['label']; } return $title; @@ -459,11 +499,11 @@ function o2_page_title( $title ) { function page_title( $title_parts ) { $active_filter = get_active_filter(); - if ( $active_filter === 'unresolved' ) { + if ( 'unresolved' === $active_filter ) { return [ __( 'To do', 'p2020' ) ]; } - if ( $active_filter === 'resolved' ) { + if ( 'resolved' === $active_filter ) { return [ __( 'Done', 'p2020' ) ]; } @@ -482,9 +522,9 @@ function infinite_scroll_ajax_url( $ajax_url ) { } $query_args = []; - if ( $active_filter === 'posts' ) { + if ( 'posts' === $active_filter ) { $query_args = [ 'p2filter_posts' => true ]; - } elseif ( $active_filter === 'comments' ) { + } elseif ( 'comments' === $active_filter ) { $query_args = [ 'p2filter_comments' => true ]; } $query_args['ts'] = \P2020\Filter\Unread\get_content_cutoff_ts( $active_filter ); @@ -509,9 +549,9 @@ function infinite_scroll_query_args( $query_args ) { return $query_args; } - if ( $active_filter === 'posts' ) { + if ( 'posts' === $active_filter ) { $query_args['p2filter_posts'] = true; - } elseif ( $active_filter === 'comments' ) { + } elseif ( 'comments' === $active_filter ) { $query_args['p2filter_comments'] = true; } $query_args['ts'] = \P2020\Filter\Unread\get_content_cutoff_ts( $active_filter ); diff --git a/inc/filter/unread.php b/inc/filter/unread.php index a7f21685..e66d4b0d 100644 --- a/inc/filter/unread.php +++ b/inc/filter/unread.php @@ -2,7 +2,7 @@ namespace P2020\Filter\Unread; -require_once( WPMU_PLUGIN_DIR . '/inline-terms/mentions.php' ); +require_once WPMU_PLUGIN_DIR . '/inline-terms/mentions.php'; require_lib( 'seen-posts' ); use function P2020\Filter\is_filter_active; @@ -147,7 +147,7 @@ function get_posts_after_ts( $ts = null, $limit = null, $fields = 'ids' ) { // If $ts is set, we filter on that $ts_condition = [ - 'after' => date( 'Y-m-d H:i:s e', $ts ), + 'after' => gmdate( 'Y-m-d H:i:s e', $ts ), 'inclusive' => true, ]; $args['date_query'] = [ $ts_condition ]; @@ -178,7 +178,7 @@ function get_comments_after_ts( $ts = null, $limit = null ) { ]; $ts_condition = [ - 'after' => date( 'Y-m-d H:i:s e', $ts ), + 'after' => gmdate( 'Y-m-d H:i:s e', $ts ), 'inclusive' => true, ]; @@ -217,16 +217,16 @@ function get_mentions_after_ts( $ts = null, $limit = null ) { $unread_posts = get_posts_after_ts( $ts, $limit ); foreach ( $unread_posts as $post_id ) { $post_mentions = \Jetpack_Mentions::get_post_mentions( $post_id ); - if ( in_array( $user->user_nicename, $post_mentions ) ) { - $mentions['posts'][] = $post_id; + if ( in_array( $user->user_nicename, $post_mentions, true ) ) { + $mentions['posts'][] = (int) $post_id; } } $unread_comments = get_comments_after_ts( $ts, $limit ); foreach ( $unread_comments as $comment_id ) { $comment_mentions = \Jetpack_Mentions::get_comment_mentions( $comment_id ); - if ( in_array( $user->user_nicename, $comment_mentions ) ) { - $mentions['comments'][] = $comment_id; + if ( in_array( $user->user_nicename, $comment_mentions, true ) ) { + $mentions['comments'][] = (int) $comment_id; } } @@ -284,7 +284,7 @@ function get_unread_count( $key, $limit = null ) { * @param string $content_type */ function get_content_cutoff_ts( $content_type ) { - if ( ! in_array( $content_type, [ 'posts', 'comments', 'mentions' ] ) ) { + if ( ! in_array( $content_type, [ 'posts', 'comments', 'mentions' ], true ) ) { return null; } @@ -313,12 +313,12 @@ function get_post_ids_after( $timestamp = null ) { $args = [ 'post_type' => 'post', 'fields' => 'ids', - 'posts_per_page' => - 1 + 'posts_per_page' => - 1, ]; // If $ts is set, we filter on that $ts_condition = [ - 'after' => date( 'Y-m-d H:i:s e', $timestamp ), + 'after' => gmdate( 'Y-m-d H:i:s e', $timestamp ), 'inclusive' => true, ]; $args['date_query'] = [ $ts_condition ]; @@ -408,11 +408,15 @@ function get_unseen_posts_count() { if ( ! $seen_entries ) { // no seen entries available => all unseen items - \SeenPosts\log_timing( $stat_name . '.2', $start_time, [ - 'blog_id' => $blog_id, - 'user_subscription_date' => $user_subscription_date, - 'feed_items_count' => $feed_items_count, - ] ); + \SeenPosts\log_timing( + $stat_name . '.2', + $start_time, + [ + 'blog_id' => $blog_id, + 'user_subscription_date' => $user_subscription_date, + 'feed_items_count' => $feed_items_count, + ] + ); return $feed_items_count; } @@ -426,12 +430,16 @@ function get_unseen_posts_count() { } $seen_count = $seen_counts[ $feed_id ]; - \SeenPosts\log_timing( $stat_name . '.3', $start_time, [ - 'blog_id' => $blog_id, - 'user_subscription_date' => $user_subscription_date, - 'feed_items_count' => $feed_items_count, - 'seen_count' => $seen_count - ] ); + \SeenPosts\log_timing( + $stat_name . '.3', + $start_time, + [ + 'blog_id' => $blog_id, + 'user_subscription_date' => $user_subscription_date, + 'feed_items_count' => $feed_items_count, + 'seen_count' => $seen_count, + ] + ); return max( $feed_items_count - $seen_count, 0 ); } @@ -483,15 +491,19 @@ function get_unseen_blog_posts( $user_subscription_timestamp ) { $seen_post_ids[] = $post_object->post_id; } - \SeenPosts\log_timing( $stat_name . '.4', $start_time, [ - 'blog_id' => $blog_id, - 'feed_id' => $feed_id, - 'user_subscription_timestamp' => $user_subscription_timestamp, - 'blog_posts_ids' => count( $blog_posts_ids ), - 'feed_items' => count( $feed_items ), - 'feed_items_data' => count( $feed_items_data ), - 'seen_post_ids' => count( $seen_post_ids ) - ] ); + \SeenPosts\log_timing( + $stat_name . '.4', + $start_time, + [ + 'blog_id' => $blog_id, + 'feed_id' => $feed_id, + 'user_subscription_timestamp' => $user_subscription_timestamp, + 'blog_posts_ids' => count( $blog_posts_ids ), + 'feed_items' => count( $feed_items ), + 'feed_items_data' => count( $feed_items_data ), + 'seen_post_ids' => count( $seen_post_ids ), + ] + ); return array_diff( $blog_posts_ids, $seen_post_ids ); } diff --git a/inc/follow/follow.php b/inc/follow/follow.php index 462018e2..985c1d91 100644 --- a/inc/follow/follow.php +++ b/inc/follow/follow.php @@ -7,14 +7,14 @@ function enqueue_scripts() { } function scripts() { - wp_enqueue_script( 'p2020-follow', get_template_directory_uri() . '/inc/follow/js/follow.js', [ 'jquery' ], false, true ); + wp_enqueue_script( 'p2020-follow', get_template_directory_uri() . '/inc/follow/js/follow.js', [ 'jquery' ], '20200801', true ); $data = [ 'isUserLoggedIn' => is_user_logged_in(), - 'nonce' => wp_create_nonce( 'manage_subscription' ), - 'followText' => __( 'Follow', 'p2020' ), - 'unfollowText' => __( 'Unfollow', 'p2020' ), - 'followingText' => __( 'Following', 'p2020' ), + 'nonce' => wp_create_nonce( 'manage_subscription' ), + 'followText' => __( 'Follow', 'p2020' ), + 'unfollowText' => __( 'Unfollow', 'p2020' ), + 'followingText' => __( 'Following', 'p2020' ), ]; wp_localize_script( 'p2020-follow', 'p2020FollowData', $data ); @@ -26,13 +26,15 @@ function render() { return; } - $is_following = wpcom_subs_is_subscribed( [ - 'user_id' => get_current_user_id(), - 'blog_id' => $blog_id, - ] ); - $label = $is_following ? __( 'Following', 'p2020' ) : __( 'Follow', 'p2020' ); - $class = $is_following ? 'unfollow' : 'follow'; + $is_following = wpcom_subs_is_subscribed( + [ + 'user_id' => get_current_user_id(), + 'blog_id' => $blog_id, + ] + ); + $label = $is_following ? __( 'Following', 'p2020' ) : __( 'Follow', 'p2020' ); + $class = $is_following ? 'unfollow' : 'follow'; echo ''; } diff --git a/inc/jetpack.php b/inc/jetpack.php index f91bcbaf..f719d953 100644 --- a/inc/jetpack.php +++ b/inc/jetpack.php @@ -13,17 +13,20 @@ * See: http://jetpack.me/support/infinite-scroll/ */ function infinite_scroll_setup() { - $footer = 'main'; + $footer = 'main'; $is_tablet = ( class_exists( 'Jetpack_User_Agent_Info' ) ) ? \Jetpack_User_Agent_Info::is_tablet() : false; if ( $is_tablet ) { // don't show the infinite scroll footer on tablet devices (infinite scroll will still work) $footer = false; } - add_theme_support( 'infinite-scroll', [ - 'container' => 'content', - 'footer' => $footer, - ] ); + add_theme_support( + 'infinite-scroll', + [ + 'container' => 'content', + 'footer' => $footer, + ] + ); } add_action( 'after_setup_theme', 'P2020\infinite_scroll_setup' ); @@ -32,8 +35,9 @@ function infinite_scroll_setup() { */ if ( function_exists( 'jetpack_is_mobile' ) ) { function has_footer_widgets() { - if ( jetpack_is_mobile( '', true ) && is_active_sidebar( 'sidebar-1' ) ) + if ( jetpack_is_mobile( '', true ) && is_active_sidebar( 'sidebar-1' ) ) { return true; + } return false; } @@ -44,8 +48,11 @@ function has_footer_widgets() { * Add theme support for o2. */ function o2_setup() { - add_theme_support( 'o2', [ - 'o2_enabled' => true, - ] ); + add_theme_support( + 'o2', + [ + 'o2_enabled' => true, + ] + ); } add_action( 'after_setup_theme', 'P2020\o2_setup' ); diff --git a/inc/menu/menu.php b/inc/menu/menu.php index 05578bb2..de3058ae 100644 --- a/inc/menu/menu.php +++ b/inc/menu/menu.php @@ -9,28 +9,28 @@ function enqueue_scripts() { } function scripts() { - wp_enqueue_script( 'p2020-menu-tree', get_template_directory_uri() . '/inc/menu/js/tree.js', [ 'jquery' ] ); + wp_enqueue_script( 'p2020-menu-tree', get_template_directory_uri() . '/inc/menu/js/tree.js', [ 'jquery' ], '20200801', true ); } function render_page_menu() { $options = [ - 'title_li' => '', + 'title_li' => '', 'sort_column' => 'menu_order, post_title', - 'exclude' => '', - 'echo' => false, - 'container' => 'div', - 'menu_class' => 'p2020-sidebar-menu p2020-sidebar-menu__pages', - 'show_home' => false, + 'exclude' => '', + 'echo' => false, + 'container' => 'div', + 'menu_class' => 'p2020-sidebar-menu p2020-sidebar-menu__pages', + 'show_home' => false, ]; $pages_html = wp_page_menu( $options ); // empty list $container = $options['container']; - $classes = $options['menu_class']; - if ( $pages_html === "<$container class=\"$classes\">" ) { - $scheme = is_ssl() ? 'https' : 'http'; - $site_slug = \WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() ); + $classes = $options['menu_class']; + if ( "<$container class=\"$classes\">" === $pages_html ) { + $scheme = is_ssl() ? 'https' : 'http'; + $site_slug = \WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() ); $page_editor_link = "{$scheme}://wordpress.com/block-editor/page/{$site_slug}"; echo html_output( '
No documents — Start one
' ); @@ -47,12 +47,14 @@ function render_page_menu() { function render_nav_menu() { $menu_locations = get_nav_menu_locations(); - $nav_html = wp_nav_menu( [ - 'echo' => false, - 'container' => 'div', - 'container_class' => 'p2020-sidebar-menu p2020-sidebar-menu__nav', - 'menu' => $menu_locations['primary'] ?? null, - ] ); + $nav_html = wp_nav_menu( + [ + 'echo' => false, + 'container' => 'div', + 'container_class' => 'p2020-sidebar-menu p2020-sidebar-menu__nav', + 'menu' => $menu_locations['primary'] ?? null, + ] + ); if ( ! empty( $nav_html ) ) { $nav_html = format_items( 'nav', $nav_html ); @@ -77,24 +79,24 @@ function render_nav_menu() { * */ function format_items( $menu_type, $menu_html ) { - if ( $menu_type === 'pages' ) { + if ( 'pages' === $menu_type ) { $pattern = '/(
  • ]*page-item-([0-9]+)[^>]*>)]*>([^<]*)<\/a>/i'; } else { $pattern = '/(
  • )(.*)<\/a>/i'; } - $site_slug = \WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() ); + $site_slug = \WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() ); $page_editor_link = "https://wordpress.com/block-editor/page/{$site_slug}"; - $replacement = '$1 + $replacement = '$1 $4'; - if ( $menu_type === 'pages' ) { + if ( 'pages' === $menu_type ) { $replacement .= '' . __( 'New subdocument', 'p2020' ) . ''; } $replacement .= ''; - $menu_html = preg_replace( $pattern, $replacement, $menu_html ); + $menu_html = preg_replace( $pattern, $replacement, $menu_html ); return $menu_html; } @@ -105,10 +107,10 @@ function format_items( $menu_type, $menu_html ) { */ function normalize_classnames( $pages_html ) { $classnames = [ - 'page_item' => 'page-item', + 'page_item' => 'page-item', 'page_item_has_children' => 'page-item-has-children', - 'current_page_item' => 'current-page-item', - 'current_page_ancestor' => 'current-page-ancestor', + 'current_page_item' => 'current-page-item', + 'current_page_ancestor' => 'current-page-ancestor', ]; foreach ( $classnames as $original => $replacement ) { $pages_html = preg_replace( "/(\b)$original(\b)/", "$1$replacement$2", $pages_html ); diff --git a/inc/vendor/Color.php b/inc/vendor/Color.php index f91752f3..df51abbf 100644 --- a/inc/vendor/Color.php +++ b/inc/vendor/Color.php @@ -1,4 +1,5 @@ @@ -335,7 +336,7 @@ public function complementary() { // Return the new value in HEX return self::hslToHex($hsl); } - + /** * Returns your color's HSL array */ @@ -354,7 +355,7 @@ public function getHex() { public function getRgb() { return $this->_rgb; } - + /** * Returns the cross browser CSS3 gradient * @param int $amount Optional: percentage amount to light/darken the gradient @@ -516,7 +517,7 @@ private static function _checkHex( $hex ) { return $color; } - + /** * Converts object into its string representation * @return string Color @@ -594,4 +595,4 @@ public function __set($name, $value) } } } -?> \ No newline at end of file +?> diff --git a/index.php b/index.php index 19a8c96e..cc51902d 100644 --- a/index.php +++ b/index.php @@ -27,20 +27,23 @@
    - + diff --git a/js/vendor/html5.js b/js/vendor/html5.js deleted file mode 100644 index bbce057c..00000000 --- a/js/vendor/html5.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! HTML5 Shiv v3.6 stable | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed */ -(function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag(); -a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x"; -c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^<|^(?:a|b|button|code|div|fieldset|form|h1|h2|h3|h4|h5|h6|i|iframe|img|input|label|li|link|ol|option|p|param|q|script|select|span|strong|style|table|tbody|td|textarea|tfoot|th|thead|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a"); -var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode||"undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header mark meter nav output progress section summary time video",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a, -b){a||(a=f);if(g)return a.createDocumentFragment();for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d
    - +
    diff --git a/partials/logo-p2.php b/partials/logo-p2.php index 9cf099bb..d99c0f74 100644 --- a/partials/logo-p2.php +++ b/partials/logo-p2.php @@ -6,6 +6,7 @@ */ namespace P2020; + ?>

    @@ -32,7 +32,7 @@ class="p2020-sidebar-header__mobile-toggle-button"
    diff --git a/partials/sidebar-info.php b/partials/sidebar-info.php index da0db072..d45e364e 100644 --- a/partials/sidebar-info.php +++ b/partials/sidebar-info.php @@ -7,16 +7,16 @@ namespace P2020; -require_once( get_template_directory() . '/inc/class-ellipsis-menu.php' ); -require_once( get_template_directory() . '/inc/filter/filter.php' ); -require_once( get_template_directory() . '/inc/follow/follow.php' ); +require_once get_template_directory() . '/inc/class-ellipsis-menu.php'; +require_once get_template_directory() . '/inc/filter/filter.php'; +require_once get_template_directory() . '/inc/follow/follow.php'; $site_slug = \WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() ); -$return_home_param = '?return=' . esc_url( get_blog_url() ); -$customizer_url = 'https://wordpress.com/customize/' . $site_slug . $return_home_param; +$return_home_param = '?return=' . esc_url( get_blog_url() ); +$customizer_url = 'https://wordpress.com/customize/' . $site_slug . $return_home_param; $customizer_identity_url = 'https://wordpress.com/customize/identity/' . $site_slug . $return_home_param; -$settings_url = 'https://wordpress.com/settings/general/' . $site_slug; +$settings_url = 'https://wordpress.com/settings/general/' . $site_slug; $header_image_height = get_theme_support( 'custom-header', 'height' ) / 2 . 'px'; ?> @@ -30,15 +30,15 @@ title="" rel="home" > - + - +
    - +
    add_item( __( 'Upload a header image', 'p2020' ), $customizer_identity_url ); - } - if ( current_user_can( 'customize' ) ) { - $info_menu->add_item( __( 'Customize sidebar', 'p2020' ), $customizer_url ); - } - if ( current_user_can( 'manage_options' ) ) { - $info_menu->add_item( __( 'Site settings', 'p2020' ), $settings_url ); - } + if ( current_user_can( 'customize' ) && ! has_header_image() ) { + $info_menu->add_item( __( 'Upload a header image', 'p2020' ), $customizer_identity_url ); + } + if ( current_user_can( 'customize' ) ) { + $info_menu->add_item( __( 'Customize sidebar', 'p2020' ), $customizer_url ); + } + if ( current_user_can( 'manage_options' ) ) { + $info_menu->add_item( __( 'Site settings', 'p2020' ), $settings_url ); + } echo html_output( $info_menu->generate() ); ?>
    diff --git a/search.php b/search.php index d674c668..dcffa775 100644 --- a/search.php +++ b/search.php @@ -10,7 +10,10 @@
    - +
    diff --git a/sidebar.php b/sidebar.php index 71a1296f..6edbc446 100644 --- a/sidebar.php +++ b/sidebar.php @@ -7,21 +7,26 @@ namespace P2020; -require_once( get_template_directory() . '/inc/class-ellipsis-menu.php' ); -require_once( get_template_directory() . '/inc/menu/menu.php' ); +require_once get_template_directory() . '/inc/class-ellipsis-menu.php'; +require_once get_template_directory() . '/inc/menu/menu.php'; use function \P2020\html_output; $site_slug = \WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() ); -$signup_url = 'https://wordpress.com/start/p2'; +$signup_url = 'https://wordpress.com/start/p2'; $customizer_menu_url = 'https://wordpress.com/customize/menus/' . $site_slug; -$help_url = 'https://wordpress.com/help'; -$pages_url = 'https://wordpress.com/pages/' . $site_slug; -$editor_page_url = 'https://wordpress.com/block-editor/page/' . $site_slug; +$help_url = 'https://wordpress.com/help'; +$pages_url = 'https://wordpress.com/pages/' . $site_slug; +$editor_page_url = 'https://wordpress.com/block-editor/page/' . $site_slug; ?> -