diff --git a/admin/apple-actions/index/class-push.php b/admin/apple-actions/index/class-push.php index 1090a9fab..f36b552d8 100644 --- a/admin/apple-actions/index/class-push.php +++ b/admin/apple-actions/index/class-push.php @@ -214,7 +214,7 @@ private function push( $user_id = null ) { } // Get the isPreview setting. - $is_paid = (bool) get_post_meta( $this->id, 'apple_news_is_paid', true ); + $is_paid = (bool) get_post_meta( $this->id, 'apple_news_is_paid', true ); $meta['data']['isPaid'] = $is_paid; // Get the isPreview setting. diff --git a/admin/class-admin-apple-bulk-export-page.php b/admin/class-admin-apple-bulk-export-page.php index bd3a21253..3de6236c4 100644 --- a/admin/class-admin-apple-bulk-export-page.php +++ b/admin/class-admin-apple-bulk-export-page.php @@ -83,7 +83,7 @@ public function set_title( $admin_title ) { * @access public */ public function build_page() { - $ids = isset( $_GET['ids'] ) ? sanitize_text_field( wp_unslash( $_GET['ids'] ) ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected + $ids = isset( $_GET['ids'] ) ? sanitize_text_field( wp_unslash( $_GET['ids'] ) ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended if ( ! $ids ) { wp_safe_redirect( esc_url_raw( menu_page_url( $this->plugin_slug . '_index', false ) ) ); if ( ! defined( 'APPLE_NEWS_UNIT_TESTS' ) || ! APPLE_NEWS_UNIT_TESTS ) { diff --git a/admin/class-admin-apple-index-page.php b/admin/class-admin-apple-index-page.php index 651c7140b..376d347ff 100644 --- a/admin/class-admin-apple-index-page.php +++ b/admin/class-admin-apple-index-page.php @@ -92,8 +92,8 @@ public function setup_admin_page() { * @access public */ public function admin_page() { - $id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected - $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected + $id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended + $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended switch ( $action ) { case self::namespace_action( 'push' ): @@ -127,9 +127,9 @@ public function admin_page() { * @return mixed The result of the requested action. */ public function page_router() { - $id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected - $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected - $action2 = isset( $_GET['action2'] ) ? sanitize_text_field( wp_unslash( $_GET['action2'] ) ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected + $id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended + $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended + $action2 = isset( $_GET['action2'] ) ? sanitize_text_field( wp_unslash( $_GET['action2'] ) ) : null; // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended // Allow for bulk actions from top or bottom. if ( ( empty( $action ) || '-1' === $action ) && ! empty( $action2 ) ) { @@ -145,8 +145,8 @@ public function page_router() { case self::namespace_action( 'push' ): // phpcs:ignore PSR2.ControlStructures.SwitchDeclaration.TerminatingComment if ( ! $id ) { $url = menu_page_url( $this->plugin_slug . '_bulk_export', false ); - if ( isset( $_GET['article'] ) ) { // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected - $ids = is_array( $_GET['article'] ) ? array_map( 'absint', $_GET['article'] ) : absint( $_GET['article'] ); // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected + if ( isset( $_GET['article'] ) ) { // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended + $ids = is_array( $_GET['article'] ) ? array_map( 'absint', $_GET['article'] ) : absint( $_GET['article'] ); // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended $url .= '&ids=' . implode( '.', $ids ); } wp_safe_redirect( esc_url_raw( $url ) ); @@ -233,8 +233,8 @@ public static function action_query_params( $action, $url ) { // Add the other params. foreach ( $keys as $key ) { - if ( ! empty( $_GET[ $key ] ) ) { // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected - $params[ $key ] = rawurlencode( sanitize_text_field( wp_unslash( $_GET[ $key ] ) ) ); // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected + if ( ! empty( $_GET[ $key ] ) ) { // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended + $params[ $key ] = rawurlencode( sanitize_text_field( wp_unslash( $_GET[ $key ] ) ) ); // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended } } diff --git a/admin/class-admin-apple-json.php b/admin/class-admin-apple-json.php index a0bbfa9d3..5b14d150e 100644 --- a/admin/class-admin-apple-json.php +++ b/admin/class-admin-apple-json.php @@ -425,8 +425,8 @@ public function get_selected_theme() { } // Next, check for a theme loaded in from the query string. - if ( ! empty( $_GET['theme'] ) ) { // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected - return sanitize_text_field( wp_unslash( $_GET['theme'] ) ); // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected + if ( ! empty( $_GET['theme'] ) ) { // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended + return sanitize_text_field( wp_unslash( $_GET['theme'] ) ); // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.Security.NonceVerification.Recommended } return ''; diff --git a/admin/class-admin-apple-meta-boxes.php b/admin/class-admin-apple-meta-boxes.php index db7ede0f0..1b76b7818 100644 --- a/admin/class-admin-apple-meta-boxes.php +++ b/admin/class-admin-apple-meta-boxes.php @@ -314,7 +314,7 @@ public static function build_sections_field( $post_id ) { foreach ( $sections as $section ) { ?>
'POST', 'callback' => function( $data ) { - $body = json_decode( $data->get_body(), true ); + $body = json_decode( $data->get_body(), true ); $notifications = ! empty( $body['toClear'] ) && is_array( $body['toClear'] ) ? $body['toClear'] : []; diff --git a/includes/REST/apple-news-delete.php b/includes/REST/apple-news-delete.php index 39f1fc613..25a4e0a4a 100644 --- a/includes/REST/apple-news-delete.php +++ b/includes/REST/apple-news-delete.php @@ -4,6 +4,7 @@ * * @package Apple_News */ + namespace Apple_News\REST; use \WP_Error; diff --git a/includes/REST/apple-news-get-published-state.php b/includes/REST/apple-news-get-published-state.php index ef6938354..73f8413d0 100644 --- a/includes/REST/apple-news-get-published-state.php +++ b/includes/REST/apple-news-get-published-state.php @@ -4,7 +4,9 @@ * * @package Apple_News */ + namespace Apple_News\REST; + /** * Get API response. * @@ -12,13 +14,13 @@ * @return array updated response. */ function get_published_state_response( $data ) { - $response = []; + $response = []; if ( ! empty( get_current_user_id() ) ) { $response['publishState'] = \Admin_Apple_News::get_post_status( $data['id'] ); } - return $response; + return $response; } /** diff --git a/includes/REST/apple-news-get-settings.php b/includes/REST/apple-news-get-settings.php index 3e4472b40..0a690640c 100644 --- a/includes/REST/apple-news-get-settings.php +++ b/includes/REST/apple-news-get-settings.php @@ -4,7 +4,9 @@ * * @package Apple_News */ + namespace Apple_News\REST; + /** * Get API response. * @@ -18,7 +20,7 @@ function get_settings_response( $data ) { // Compile non-sensitive plugin settings into a JS-friendly format and return. $admin_settings = new \Admin_Apple_Settings(); - $settings = $admin_settings->fetch_settings(); + $settings = $admin_settings->fetch_settings(); return [ 'adminUrl' => esc_url_raw( admin_url( 'admin.php?page=apple-news-options' ) ), 'automaticAssignment' => ! empty( get_option( 'apple_news_section_taxonomy_mappings' ) ), diff --git a/includes/REST/apple-news-modify-post.php b/includes/REST/apple-news-modify-post.php index f70610fdd..b2980c89b 100644 --- a/includes/REST/apple-news-modify-post.php +++ b/includes/REST/apple-news-modify-post.php @@ -4,6 +4,7 @@ * * @package Apple_News */ + namespace Apple_News\REST; use \Admin_Apple_News; @@ -76,7 +77,7 @@ function modify_post( $post_id, $operation ) { $action = new Push( Admin_Apple_News::$settings, $post_id ); break; case 'delete': - $action = new Delete( Admin_Apple_News::$settings, $post_id ); + $action = new Delete( Admin_Apple_News::$settings, $post_id ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_delete break; default: $message = __( 'You specified an invalid API operation.', 'apple-news' ); @@ -85,7 +86,6 @@ function modify_post( $post_id, $operation ) { 'apple_news_bad_operation', $message ); - break; } try { $action->perform(); @@ -96,6 +96,7 @@ function modify_post( $post_id, $operation ) { } elseif ( 'delete' === $operation ) { Admin_Apple_Notice::success( sprintf( + // translators: The title of the article. __( 'Article %s has been successfully deleted from Apple News!', 'apple-news' ), $post->post_title ) diff --git a/includes/REST/apple-news-publish.php b/includes/REST/apple-news-publish.php index 89b1e45b0..937e42954 100644 --- a/includes/REST/apple-news-publish.php +++ b/includes/REST/apple-news-publish.php @@ -4,6 +4,7 @@ * * @package Apple_News */ + namespace Apple_News\REST; use \WP_Error; diff --git a/includes/REST/apple-news-sections.php b/includes/REST/apple-news-sections.php index d492c703f..3a755827c 100644 --- a/includes/REST/apple-news-sections.php +++ b/includes/REST/apple-news-sections.php @@ -1,30 +1,31 @@ esc_html( 'https://news-api.apple.com/sections/' . $section->id ), - 'name' => esc_html( $section->name ), - ]; - } - } + if ( ! empty( $sections ) && ! empty( get_current_user_id() ) ) { + foreach ( $sections as $section ) { + $response[] = [ + 'id' => esc_html( 'https://news-api.apple.com/sections/' . $section->id ), + 'name' => esc_html( $section->name ), + ]; + } + } - return $response; + return $response; } /** diff --git a/includes/REST/apple-news-update.php b/includes/REST/apple-news-update.php index 20d023ebd..09940ac53 100644 --- a/includes/REST/apple-news-update.php +++ b/includes/REST/apple-news-update.php @@ -4,6 +4,7 @@ * * @package Apple_News */ + namespace Apple_News\REST; use \WP_Error; diff --git a/includes/REST/apple-news-user-can-publish.php b/includes/REST/apple-news-user-can-publish.php index 4aed9f740..08fb3dae7 100644 --- a/includes/REST/apple-news-user-can-publish.php +++ b/includes/REST/apple-news-user-can-publish.php @@ -4,6 +4,7 @@ * * @package Apple_News */ + namespace Apple_News\REST; use \Apple_News; diff --git a/includes/apple-exporter/builders/class-text-styles.php b/includes/apple-exporter/builders/class-text-styles.php index 972fb94e5..c27ee1838 100644 --- a/includes/apple-exporter/builders/class-text-styles.php +++ b/includes/apple-exporter/builders/class-text-styles.php @@ -27,7 +27,7 @@ class Text_Styles extends Builder { * @access private * @var array */ - private $_styles = array(); + private $styles = array(); /** * Constructor. @@ -61,7 +61,7 @@ public function build() { * * @param array $styles The styles to be filtered. */ - return apply_filters( 'apple_news_text_styles', $this->_styles ); + return apply_filters( 'apple_news_text_styles', $this->styles ); } /** @@ -75,12 +75,12 @@ public function build() { public function register_style( $name, $values ) { // Only register once, since styles have unique names. - if ( array_key_exists( $name, $this->_styles ) ) { + if ( array_key_exists( $name, $this->styles ) ) { return; } // Register the style. - $this->_styles[ $name ] = $values; + $this->styles[ $name ] = $values; } /** diff --git a/includes/apple-exporter/class-component-factory.php b/includes/apple-exporter/class-component-factory.php index d17df9385..c009734cc 100644 --- a/includes/apple-exporter/class-component-factory.php +++ b/includes/apple-exporter/class-component-factory.php @@ -197,13 +197,13 @@ public static function get_components_from_node( $node ) { } // We matched a single node. - $html = $node->ownerDocument->saveXML( $matched_node ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar + $html = $node->ownerDocument->saveXML( $matched_node ); $result[] = self::get_component( $shortname, $html ); return $result; } // Nothing found. Maybe it's a container element? if ( $node->hasChildNodes() ) { - foreach ( $node->childNodes as $child ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar + foreach ( $node->childNodes as $child ) { $result = array_merge( $result, self::get_components_from_node( $child, $node ) ); } // Remove all nulls from the array. @@ -216,8 +216,8 @@ public static function get_components_from_node( $node ) { * Others nodes without a match are almost always just stray empty text nodes * that are always safe to remove. Paragraphs should also be ignored for this reason. */ - if ( empty( $result ) && ( ! empty( $node->tagName ) && 'p' !== $node->tagName ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar - self::$workspace->log_error( 'component_errors', $node->tagName ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar + if ( empty( $result ) && ( ! empty( $node->tagName ) && 'p' !== $node->tagName ) ) { + self::$workspace->log_error( 'component_errors', $node->tagName ); } return $result; diff --git a/includes/apple-exporter/class-exporter-content.php b/includes/apple-exporter/class-exporter-content.php index e4ee1747c..4f0e14c52 100644 --- a/includes/apple-exporter/class-exporter-content.php +++ b/includes/apple-exporter/class-exporter-content.php @@ -231,7 +231,7 @@ public function nodes() { libxml_clear_errors( true ); // Find the first-level nodes of the body tag. - return $dom->getElementsByTagName( 'body' )->item( 0 )->childNodes; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar + return $dom->getElementsByTagName( 'body' )->item( 0 )->childNodes; } } diff --git a/includes/apple-exporter/class-html.php b/includes/apple-exporter/class-html.php index bfa5b0bae..2fe62f5d4 100644 --- a/includes/apple-exporter/class-html.php +++ b/includes/apple-exporter/class-html.php @@ -24,7 +24,7 @@ class HTML { * @access private * @var array */ - private $_allowed_html = array( + private $allowed_html = array( 'a' => array( 'href' => true, ), @@ -71,7 +71,7 @@ public function format( $html ) { $html = preg_replace( '/