PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | modules/markdown/easy-markdown.php +26 -10 13.6.2 → 16.3-a.7 View file →
@@ -32,8 +32,12 @@
32 32 * GNU General Public License for more details.
33 33 * **********************************************************************
34 34 */
35 35
36 +if ( ! defined( 'ABSPATH' ) ) {
37 + exit( 0 );
38 +}
39 +
36 40 /**
37 41 * WPCom_Markdown class.
38 42 */
39 43 class WPCom_Markdown {
@@ -74,8 +78,15 @@
74 78 'parent' => array(),
75 79 );
76 80
77 81 /**
82 + * Whether or not kses filters were removed. Only set if removal was attempted.
83 + *
84 + * @var ?bool
85 + */
86 + public $kses;
87 +
88 + /**
78 89 * Yay singletons!
79 90 *
80 91 * @return object WPCom_Markdown instance
81 92 */
@@ -92,8 +103,9 @@
92 103 public function load() {
93 104 $this->add_default_post_type_support();
94 105 $this->maybe_load_actions_and_filters();
95 106 if ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) {
107 + // phpcs:ignore WPCUT.SwitchBlog.SwitchBlog -- wpcom flags **every** use of switch_blog, apparently expecting valid instances to ignore or suppress the sniff.
96 108 add_action( 'switch_blog', array( $this, 'maybe_load_actions_and_filters' ), 10, 2 );
97 109 }
98 110 add_action( 'admin_init', array( $this, 'register_setting' ) );
99 111 add_action( 'admin_init', array( $this, 'maybe_unload_for_bulk_edit' ) );
@@ -169,12 +181,12 @@
169 181 public function unload_markdown_for_posts() {
170 182 remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ) );
171 183 remove_action( 'after_wp_tiny_mce', array( $this, 'after_wp_tiny_mce' ) );
172 184 remove_action( 'wp_insert_post', array( $this, 'wp_insert_post' ) );
173 - remove_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 10, 2 );
174 - remove_filter( 'edit_post_content', array( $this, 'edit_post_content' ), 10, 2 );
175 - remove_filter( 'edit_post_content_filtered', array( $this, 'edit_post_content_filtered' ), 10, 2 );
176 - remove_action( 'wp_restore_post_revision', array( $this, 'wp_restore_post_revision' ), 10, 2 );
185 + remove_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 10 );
186 + remove_filter( 'edit_post_content', array( $this, 'edit_post_content' ), 10 );
187 + remove_filter( 'edit_post_content_filtered', array( $this, 'edit_post_content_filtered' ), 10 );
188 + remove_action( 'wp_restore_post_revision', array( $this, 'wp_restore_post_revision' ), 10 );
177 189 remove_filter( '_wp_post_revision_fields', array( $this, 'wp_post_revision_fields' ) );
178 190 remove_action( 'xmlrpc_call', array( $this, 'xmlrpc_actions' ) );
179 191 remove_filter( 'content_save_pre', array( $this, 'preserve_code_blocks' ), 1 );
180 192 }
@@ -304,9 +316,9 @@
304 316 '<label><input name="%1$s" id="%1$s" type="checkbox"%2$s /> %3$s</label><p class="description">%4$s</p>',
305 317 esc_attr( self::POST_OPTION ),
306 318 checked( $this->is_posting_enabled(), true, false ),
307 319 esc_html__( 'Use Markdown for posts and pages.', 'jetpack' ),
308 - sprintf( '<a href="%s">%s</a>', esc_url( $this->get_support_url() ), esc_html__( 'Learn more about Markdown.', 'jetpack' ) )
320 + sprintf( '<a href="%s" data-target="wpcom-help-center">%s</a>', esc_url( $this->get_support_url() ), esc_html__( 'Learn more about Markdown.', 'jetpack' ) )
309 321 );
310 322 }
311 323
312 324 /**
@@ -317,9 +329,9 @@
317 329 '<label><input name="%1$s" id="%1$s" type="checkbox"%2$s /> %3$s</label><p class="description">%4$s</p>',
318 330 esc_attr( self::COMMENT_OPTION ),
319 331 checked( $this->is_commenting_enabled(), true, false ),
320 332 esc_html__( 'Use Markdown for comments.', 'jetpack' ),
321 - sprintf( '<a href="%s">%s</a>', esc_url( $this->get_support_url() ), esc_html__( 'Learn more about Markdown.', 'jetpack' ) )
333 + sprintf( '<a href="%s" data-target="wpcom-help-center">%s</a>', esc_url( $this->get_support_url() ), esc_html__( 'Learn more about Markdown.', 'jetpack' ) )
322 334 );
323 335 }
324 336
325 337 /**
@@ -527,9 +539,9 @@
527 539 * @return array $post_data with post_content and post_content_filtered modified
528 540 */
529 541 public function wp_insert_post_data( $post_data, $postarr ) {
530 542 // $post_data array is slashed!
531 - $post_id = isset( $postarr['ID'] ) ? $postarr['ID'] : false;
543 + $post_id = $postarr['ID'] ?? false;
532 544 // bail early if markdown is disabled or this post type is unsupported.
533 545 if ( ! $this->is_posting_enabled() || ! post_type_supports( $post_data['post_type'], self::POST_TYPE_SUPPORT ) ) {
534 546 // it's disabled, but maybe this *was* a markdown post before.
535 547 if ( $this->is_markdown( $post_id ) && ! empty( $post_data['post_content_filtered'] ) ) {
@@ -665,9 +677,9 @@
665 677 *
666 678 * @param string $text Content to be run through Markdown
667 679 * @param array $args Array of Markdown options.
668 680 */
669 - $text = apply_filters( 'wpcom_markdown_transform_pre', $text, $args );
681 + $text = apply_filters( 'wpcom_markdown_transform_pre', $text, $args ) ?? '';
670 682 // ensure our paragraphs are separated.
671 683 $text = str_replace( array( '</p><p>', "</p>\n<p>" ), "</p>\n\n<p>", $text );
672 684 // visual editor likes to add <p>s. Buh-bye.
673 685 $text = $this->get_parser()->unp( $text );
@@ -786,9 +798,9 @@
786 798 include_once ABSPATH . WPINC . '/class-IXR.php';
787 799 $message = new IXR_Message( $raw_post_data );
788 800 $message->parse();
789 801 $post_id_position = 'metaWeblog.getPost' === $message->methodName ? 0 : 1; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
790 - $this->prime_post_cache( $message->params[ $post_id_position ] );
802 + $this->prime_post_cache( $message->params[ $post_id_position ] ?? false );
791 803 }
792 804
793 805 /**
794 806 * Prime the post cache with swapped post_content. This is a sneaky way of getting around
@@ -798,9 +810,13 @@
798 810 */
799 811 private function prime_post_cache( $post_id = false ) {
800 812 global $wp_xmlrpc_server;
801 813 if ( ! $post_id ) {
802 - $post_id = $wp_xmlrpc_server->message->params[3];
814 + if ( isset( $wp_xmlrpc_server->message->params[3] ) ) {
815 + $post_id = $wp_xmlrpc_server->message->params[3];
816 + } else {
817 + return; // Exit early if we can't get a valid post_id
818 + }
803 819 }
804 820
805 821 // prime the post cache.
806 822 if ( $this->is_markdown( $post_id ) ) {