Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/markdown
File: easy-markdown.php
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
/**
[1] Fix | Delete
* Plugin URI: https://automattic.com/
[2] Fix | Delete
* Plugin Name: Easy Markdown
[3] Fix | Delete
* Description: Write in Markdown, publish in WordPress
[4] Fix | Delete
* Version: 0.1
[5] Fix | Delete
* Author: Matt Wiebe
[6] Fix | Delete
* Author URI: https://automattic.com/
[7] Fix | Delete
* Text Domain: jetpack
[8] Fix | Delete
*
[9] Fix | Delete
* @package automattic/jetpack
[10] Fix | Delete
*/
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Copyright (c) Automattic. All rights reserved.
[14] Fix | Delete
*
[15] Fix | Delete
* Released under the GPL license
[16] Fix | Delete
* https://www.opensource.org/licenses/gpl-license.php
[17] Fix | Delete
*
[18] Fix | Delete
* This is an add-on for WordPress
[19] Fix | Delete
* https://wordpress.org/
[20] Fix | Delete
*
[21] Fix | Delete
* **********************************************************************
[22] Fix | Delete
* This program is free software; you can redistribute it and/or modify
[23] Fix | Delete
* it under the terms of the GNU General Public License as published by
[24] Fix | Delete
* the Free Software Foundation; either version 2 of the License, or
[25] Fix | Delete
* (at your option) any later version.
[26] Fix | Delete
*
[27] Fix | Delete
* This program is distributed in the hope that it will be useful,
[28] Fix | Delete
* but WITHOUT ANY WARRANTY; without even the implied warranty of
[29] Fix | Delete
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[30] Fix | Delete
* GNU General Public License for more details.
[31] Fix | Delete
* **********************************************************************
[32] Fix | Delete
*/
[33] Fix | Delete
[34] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[35] Fix | Delete
exit( 0 );
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* WPCom_Markdown class.
[40] Fix | Delete
*/
[41] Fix | Delete
class WPCom_Markdown {
[42] Fix | Delete
[43] Fix | Delete
const POST_OPTION = 'wpcom_publish_posts_with_markdown';
[44] Fix | Delete
const COMMENT_OPTION = 'wpcom_publish_comments_with_markdown';
[45] Fix | Delete
const POST_TYPE_SUPPORT = 'wpcom-markdown';
[46] Fix | Delete
const IS_MD_META = '_wpcom_is_markdown';
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Our markdown parser.
[50] Fix | Delete
*
[51] Fix | Delete
* @var WPCom_GHF_Markdown_Parser
[52] Fix | Delete
*/
[53] Fix | Delete
private static $parser;
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* An instance of the markdown class.
[57] Fix | Delete
*
[58] Fix | Delete
* @var WPCom_Markdown
[59] Fix | Delete
*/
[60] Fix | Delete
private static $instance;
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* To ensure that our munged posts over xml-rpc are removed from the cache.
[64] Fix | Delete
*
[65] Fix | Delete
* @var array
[66] Fix | Delete
*/
[67] Fix | Delete
public $posts_to_uncache = array();
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Posts and parents to monitor.
[71] Fix | Delete
*
[72] Fix | Delete
* @var array
[73] Fix | Delete
*/
[74] Fix | Delete
private $monitoring = array(
[75] Fix | Delete
'post' => array(),
[76] Fix | Delete
'parent' => array(),
[77] Fix | Delete
);
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Whether or not kses filters were removed. Only set if removal was attempted.
[81] Fix | Delete
*
[82] Fix | Delete
* @var ?bool
[83] Fix | Delete
*/
[84] Fix | Delete
public $kses;
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Yay singletons!
[88] Fix | Delete
*
[89] Fix | Delete
* @return object WPCom_Markdown instance
[90] Fix | Delete
*/
[91] Fix | Delete
public static function get_instance() {
[92] Fix | Delete
if ( ! self::$instance ) {
[93] Fix | Delete
self::$instance = new self();
[94] Fix | Delete
}
[95] Fix | Delete
return self::$instance;
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Kicks things off on `init` action
[100] Fix | Delete
*/
[101] Fix | Delete
public function load() {
[102] Fix | Delete
$this->add_default_post_type_support();
[103] Fix | Delete
$this->maybe_load_actions_and_filters();
[104] Fix | Delete
if ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) {
[105] Fix | Delete
// phpcs:ignore WPCUT.SwitchBlog.SwitchBlog -- wpcom flags **every** use of switch_blog, apparently expecting valid instances to ignore or suppress the sniff.
[106] Fix | Delete
add_action( 'switch_blog', array( $this, 'maybe_load_actions_and_filters' ), 10, 2 );
[107] Fix | Delete
}
[108] Fix | Delete
add_action( 'admin_init', array( $this, 'register_setting' ) );
[109] Fix | Delete
add_action( 'admin_init', array( $this, 'maybe_unload_for_bulk_edit' ) );
[110] Fix | Delete
if ( current_theme_supports( 'o2' ) || class_exists( 'P2' ) ) {
[111] Fix | Delete
$this->add_o2_helpers();
[112] Fix | Delete
}
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* If we're in a bulk edit session, unload so that we don't lose our markdown metadata
[117] Fix | Delete
*/
[118] Fix | Delete
public function maybe_unload_for_bulk_edit() {
[119] Fix | Delete
if ( isset( $_REQUEST['bulk_edit'] ) && $this->is_posting_enabled() ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
[120] Fix | Delete
$this->unload_markdown_for_posts();
[121] Fix | Delete
}
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
/**
[125] Fix | Delete
* Called on init and fires on switch_blog to decide if our actions and filters
[126] Fix | Delete
* should be running.
[127] Fix | Delete
*
[128] Fix | Delete
* @param int|null $new_blog_id New blog ID.
[129] Fix | Delete
* @param int|null $old_blog_id Old blog ID.
[130] Fix | Delete
* @return null
[131] Fix | Delete
*/
[132] Fix | Delete
public function maybe_load_actions_and_filters( $new_blog_id = null, $old_blog_id = null ) {
[133] Fix | Delete
[134] Fix | Delete
// When WP sites are being installed, the options table is not available yet.
[135] Fix | Delete
if ( function_exists( 'wp_installing' ) && wp_installing() ) {
[136] Fix | Delete
return;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
// If this is a switch_to_blog call, and the blog isn't changing, we'll already be loaded.
[140] Fix | Delete
if ( $new_blog_id && $new_blog_id === $old_blog_id ) {
[141] Fix | Delete
return;
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
if ( $this->is_posting_enabled() ) {
[145] Fix | Delete
$this->load_markdown_for_posts();
[146] Fix | Delete
} else {
[147] Fix | Delete
$this->unload_markdown_for_posts();
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
if ( $this->is_commenting_enabled() ) {
[151] Fix | Delete
$this->load_markdown_for_comments();
[152] Fix | Delete
} else {
[153] Fix | Delete
$this->unload_markdown_for_comments();
[154] Fix | Delete
}
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Set up hooks for enabling Markdown conversion on posts
[159] Fix | Delete
*/
[160] Fix | Delete
public function load_markdown_for_posts() {
[161] Fix | Delete
add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 );
[162] Fix | Delete
add_action( 'after_wp_tiny_mce', array( $this, 'after_wp_tiny_mce' ) );
[163] Fix | Delete
add_action( 'wp_insert_post', array( $this, 'wp_insert_post' ) );
[164] Fix | Delete
add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 10, 2 );
[165] Fix | Delete
add_filter( 'edit_post_content', array( $this, 'edit_post_content' ), 10, 2 );
[166] Fix | Delete
add_filter( 'edit_post_content_filtered', array( $this, 'edit_post_content_filtered' ), 10, 2 );
[167] Fix | Delete
add_action( 'wp_restore_post_revision', array( $this, 'wp_restore_post_revision' ), 10, 2 );
[168] Fix | Delete
add_filter( '_wp_post_revision_fields', array( $this, 'wp_post_revision_fields' ) );
[169] Fix | Delete
add_action( 'xmlrpc_call', array( $this, 'xmlrpc_actions' ) );
[170] Fix | Delete
add_filter( 'content_save_pre', array( $this, 'preserve_code_blocks' ), 1 );
[171] Fix | Delete
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
[172] Fix | Delete
$this->check_for_early_methods();
[173] Fix | Delete
}
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
/**
[177] Fix | Delete
* Removes hooks to disable Markdown conversion on posts
[178] Fix | Delete
*/
[179] Fix | Delete
public function unload_markdown_for_posts() {
[180] Fix | Delete
remove_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ) );
[181] Fix | Delete
remove_action( 'after_wp_tiny_mce', array( $this, 'after_wp_tiny_mce' ) );
[182] Fix | Delete
remove_action( 'wp_insert_post', array( $this, 'wp_insert_post' ) );
[183] Fix | Delete
remove_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 10 );
[184] Fix | Delete
remove_filter( 'edit_post_content', array( $this, 'edit_post_content' ), 10 );
[185] Fix | Delete
remove_filter( 'edit_post_content_filtered', array( $this, 'edit_post_content_filtered' ), 10 );
[186] Fix | Delete
remove_action( 'wp_restore_post_revision', array( $this, 'wp_restore_post_revision' ), 10 );
[187] Fix | Delete
remove_filter( '_wp_post_revision_fields', array( $this, 'wp_post_revision_fields' ) );
[188] Fix | Delete
remove_action( 'xmlrpc_call', array( $this, 'xmlrpc_actions' ) );
[189] Fix | Delete
remove_filter( 'content_save_pre', array( $this, 'preserve_code_blocks' ), 1 );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
/**
[193] Fix | Delete
* Set up hooks for enabling Markdown conversion on comments
[194] Fix | Delete
*/
[195] Fix | Delete
protected function load_markdown_for_comments() {
[196] Fix | Delete
// Use priority 9 so that Markdown runs before KSES, which can clean up
[197] Fix | Delete
// any munged HTML.
[198] Fix | Delete
add_filter( 'pre_comment_content', array( $this, 'pre_comment_content' ), 9 );
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* Removes hooks to disable Markdown conversion
[203] Fix | Delete
*/
[204] Fix | Delete
protected function unload_markdown_for_comments() {
[205] Fix | Delete
remove_filter( 'pre_comment_content', array( $this, 'pre_comment_content' ), 9 );
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
/**
[209] Fix | Delete
* The o2 plugin does some of what we do. Let's take precedence.
[210] Fix | Delete
*/
[211] Fix | Delete
public function add_o2_helpers() {
[212] Fix | Delete
if ( $this->is_posting_enabled() ) {
[213] Fix | Delete
add_filter( 'content_save_pre', array( $this, 'o2_escape_lists' ), 1 );
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
add_filter( 'o2_preview_post', array( $this, 'o2_preview_post' ) );
[217] Fix | Delete
add_filter( 'o2_preview_comment', array( $this, 'o2_preview_comment' ) );
[218] Fix | Delete
[219] Fix | Delete
add_filter( 'wpcom_markdown_transform_pre', array( $this, 'o2_unescape_lists' ) );
[220] Fix | Delete
add_filter( 'wpcom_untransformed_content', array( $this, 'o2_unescape_lists' ) );
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* If Markdown is enabled for posts on this blog, filter the text for o2 previews
[225] Fix | Delete
*
[226] Fix | Delete
* @param string $text Post text.
[227] Fix | Delete
* @return string Post text transformed through the magic of Markdown
[228] Fix | Delete
*/
[229] Fix | Delete
public function o2_preview_post( $text ) {
[230] Fix | Delete
if ( $this->is_posting_enabled() ) {
[231] Fix | Delete
$text = $this->transform( $text, array( 'unslash' => false ) );
[232] Fix | Delete
}
[233] Fix | Delete
return $text;
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* If Markdown is enabled for comments on this blog, filter the text for o2 previews
[238] Fix | Delete
*
[239] Fix | Delete
* @param string $text Comment text.
[240] Fix | Delete
* @return string Comment text transformed through the magic of Markdown
[241] Fix | Delete
*/
[242] Fix | Delete
public function o2_preview_comment( $text ) {
[243] Fix | Delete
if ( $this->is_commenting_enabled() ) {
[244] Fix | Delete
$text = $this->transform( $text, array( 'unslash' => false ) );
[245] Fix | Delete
}
[246] Fix | Delete
return $text;
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Escapes lists so that o2 doesn't trounce them
[251] Fix | Delete
*
[252] Fix | Delete
* @param string $text Post/comment text.
[253] Fix | Delete
* @return string Text escaped with HTML entity for asterisk.
[254] Fix | Delete
*/
[255] Fix | Delete
public function o2_escape_lists( $text ) {
[256] Fix | Delete
return preg_replace( '/^\\* /um', '&#42; ', $text );
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
/**
[260] Fix | Delete
* Unescapes the token we inserted on o2_escape_lists
[261] Fix | Delete
*
[262] Fix | Delete
* @param string $text Post/comment text with HTML entities for asterisks.
[263] Fix | Delete
* @return string Text with the HTML entity removed
[264] Fix | Delete
*/
[265] Fix | Delete
public function o2_unescape_lists( $text ) {
[266] Fix | Delete
return preg_replace( '/^[&]\#042; /um', '* ', $text );
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
/**
[270] Fix | Delete
* Preserve code blocks from being munged by KSES before they have a chance
[271] Fix | Delete
*
[272] Fix | Delete
* @param string $text post content.
[273] Fix | Delete
* @return string post content with code blocks escaped.
[274] Fix | Delete
*/
[275] Fix | Delete
public function preserve_code_blocks( $text ) {
[276] Fix | Delete
return $this->get_parser()->codeblock_preserve( $text );
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
/**
[280] Fix | Delete
* Remove KSES if it's there. Store the result to manually invoke later if needed.
[281] Fix | Delete
*/
[282] Fix | Delete
public function maybe_remove_kses() {
[283] Fix | Delete
// Filters return true if they existed before you removed them.
[284] Fix | Delete
if ( $this->is_posting_enabled() ) {
[285] Fix | Delete
$this->kses = remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' ) && remove_filter( 'content_save_pre', 'wp_filter_post_kses' );
[286] Fix | Delete
}
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* Add our Writing and Discussion settings.
[291] Fix | Delete
*/
[292] Fix | Delete
public function register_setting() {
[293] Fix | Delete
add_settings_field( self::POST_OPTION, __( 'Markdown', 'jetpack' ), array( $this, 'post_field' ), 'writing' );
[294] Fix | Delete
register_setting( 'writing', self::POST_OPTION, array( $this, 'sanitize_setting' ) );
[295] Fix | Delete
add_settings_field( self::COMMENT_OPTION, __( 'Markdown', 'jetpack' ), array( $this, 'comment_field' ), 'discussion' );
[296] Fix | Delete
register_setting( 'discussion', self::COMMENT_OPTION, array( $this, 'sanitize_setting' ) );
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
/**
[300] Fix | Delete
* Sanitize setting. Don't really want to store "on" value, so we'll store "1" instead!
[301] Fix | Delete
*
[302] Fix | Delete
* @param string $input Value received by settings API via $_POST.
[303] Fix | Delete
* @return bool Cast to boolean.
[304] Fix | Delete
*/
[305] Fix | Delete
public function sanitize_setting( $input ) {
[306] Fix | Delete
return (bool) $input;
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
/**
[310] Fix | Delete
* Prints HTML for the Writing setting
[311] Fix | Delete
*/
[312] Fix | Delete
public function post_field() {
[313] Fix | Delete
printf(
[314] Fix | Delete
'<label><input name="%1$s" id="%1$s" type="checkbox"%2$s /> %3$s</label><p class="description">%4$s</p>',
[315] Fix | Delete
esc_attr( self::POST_OPTION ),
[316] Fix | Delete
checked( $this->is_posting_enabled(), true, false ),
[317] Fix | Delete
esc_html__( 'Use Markdown for posts and pages.', 'jetpack' ),
[318] Fix | Delete
sprintf( '<a href="%s" data-target="wpcom-help-center">%s</a>', esc_url( $this->get_support_url() ), esc_html__( 'Learn more about Markdown.', 'jetpack' ) )
[319] Fix | Delete
);
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
/**
[323] Fix | Delete
* Prints HTML for the Discussion setting
[324] Fix | Delete
*/
[325] Fix | Delete
public function comment_field() {
[326] Fix | Delete
printf(
[327] Fix | Delete
'<label><input name="%1$s" id="%1$s" type="checkbox"%2$s /> %3$s</label><p class="description">%4$s</p>',
[328] Fix | Delete
esc_attr( self::COMMENT_OPTION ),
[329] Fix | Delete
checked( $this->is_commenting_enabled(), true, false ),
[330] Fix | Delete
esc_html__( 'Use Markdown for comments.', 'jetpack' ),
[331] Fix | Delete
sprintf( '<a href="%s" data-target="wpcom-help-center">%s</a>', esc_url( $this->get_support_url() ), esc_html__( 'Learn more about Markdown.', 'jetpack' ) )
[332] Fix | Delete
);
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
/**
[336] Fix | Delete
* Get the support url for Markdown
[337] Fix | Delete
*
[338] Fix | Delete
* @uses apply_filters
[339] Fix | Delete
* @return string support url
[340] Fix | Delete
*/
[341] Fix | Delete
protected function get_support_url() {
[342] Fix | Delete
/**
[343] Fix | Delete
* Filter the Markdown support URL.
[344] Fix | Delete
*
[345] Fix | Delete
* @module markdown
[346] Fix | Delete
*
[347] Fix | Delete
* @since 2.8.0
[348] Fix | Delete
*
[349] Fix | Delete
* @param string $url Markdown support URL.
[350] Fix | Delete
*/
[351] Fix | Delete
return apply_filters( 'easy_markdown_support_url', 'https://en.support.wordpress.com/markdown-quick-reference/' );
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
/**
[355] Fix | Delete
* Is Mardown conversion for posts enabled?
[356] Fix | Delete
*
[357] Fix | Delete
* @return boolean
[358] Fix | Delete
*/
[359] Fix | Delete
public function is_posting_enabled() {
[360] Fix | Delete
return (bool) Jetpack_Options::get_option_and_ensure_autoload( self::POST_OPTION, '' );
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
/**
[364] Fix | Delete
* Is Markdown conversion for comments enabled?
[365] Fix | Delete
*
[366] Fix | Delete
* @return boolean
[367] Fix | Delete
*/
[368] Fix | Delete
public function is_commenting_enabled() {
[369] Fix | Delete
return (bool) Jetpack_Options::get_option_and_ensure_autoload( self::COMMENT_OPTION, '' );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
/**
[373] Fix | Delete
* Check if a $post_id has Markdown enabled
[374] Fix | Delete
*
[375] Fix | Delete
* @param int $post_id A post ID.
[376] Fix | Delete
* @return boolean
[377] Fix | Delete
*/
[378] Fix | Delete
public function is_markdown( $post_id ) {
[379] Fix | Delete
return get_metadata( 'post', $post_id, self::IS_MD_META, true );
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
/**
[383] Fix | Delete
* Set Markdown as enabled on a post_id. We skip over update_postmeta so we
[384] Fix | Delete
* can sneakily set metadata on post revisions, which we need.
[385] Fix | Delete
*
[386] Fix | Delete
* @param int $post_id A post ID.
[387] Fix | Delete
* @return bool The metadata was successfully set.
[388] Fix | Delete
*/
[389] Fix | Delete
protected function set_as_markdown( $post_id ) {
[390] Fix | Delete
return update_metadata( 'post', $post_id, self::IS_MD_META, true );
[391] Fix | Delete
}
[392] Fix | Delete
[393] Fix | Delete
/**
[394] Fix | Delete
* Get our Markdown parser object, optionally requiring all of our needed classes and
[395] Fix | Delete
* instantiating our parser.
[396] Fix | Delete
*
[397] Fix | Delete
* @return object WPCom_GHF_Markdown_Parser instance.
[398] Fix | Delete
*/
[399] Fix | Delete
public function get_parser() {
[400] Fix | Delete
[401] Fix | Delete
if ( ! self::$parser ) {
[402] Fix | Delete
require_once JETPACK__PLUGIN_DIR . '/_inc/lib/markdown.php';
[403] Fix | Delete
self::$parser = new WPCom_GHF_Markdown_Parser();
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
return self::$parser;
[407] Fix | Delete
}
[408] Fix | Delete
[409] Fix | Delete
/**
[410] Fix | Delete
* We don't want Markdown conversion all over the place.
[411] Fix | Delete
*/
[412] Fix | Delete
public function add_default_post_type_support() {
[413] Fix | Delete
add_post_type_support( 'post', self::POST_TYPE_SUPPORT );
[414] Fix | Delete
add_post_type_support( 'page', self::POST_TYPE_SUPPORT );
[415] Fix | Delete
add_post_type_support( 'revision', self::POST_TYPE_SUPPORT );
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
/**
[419] Fix | Delete
* Figure out the post type of the post screen we're on
[420] Fix | Delete
*
[421] Fix | Delete
* @deprecated since 10.8
[422] Fix | Delete
* @return string Current post_type
[423] Fix | Delete
*/
[424] Fix | Delete
protected function get_post_screen_post_type() {
[425] Fix | Delete
_deprecated_function( __METHOD__, 'jetpack-10.8', '' );
[426] Fix | Delete
[427] Fix | Delete
global $pagenow;
[428] Fix | Delete
$post_type = filter_input( INPUT_GET, 'post_type', FILTER_UNSAFE_RAW );
[429] Fix | Delete
$post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
[430] Fix | Delete
[431] Fix | Delete
if ( 'post-new.php' === $pagenow ) {
[432] Fix | Delete
return ! empty( $post_type ) ? $post_type : 'post';
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
if ( $post_id ) {
[436] Fix | Delete
$post_type = get_post_type( $post_id );
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
return ! empty( $post_type ) ? $post_type : 'post';
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
/**
[443] Fix | Delete
* Swap post_content and post_content_filtered for editing
[444] Fix | Delete
*
[445] Fix | Delete
* @param string $content Post content.
[446] Fix | Delete
* @param int $id post ID.
[447] Fix | Delete
* @return string Swapped content
[448] Fix | Delete
*/
[449] Fix | Delete
public function edit_post_content( $content, $id ) {
[450] Fix | Delete
if ( $this->is_markdown( $id ) ) {
[451] Fix | Delete
$post = get_post( $id );
[452] Fix | Delete
if ( $post && ! empty( $post->post_content_filtered ) ) {
[453] Fix | Delete
$post = $this->swap_for_editing( $post );
[454] Fix | Delete
return $post->post_content;
[455] Fix | Delete
}
[456] Fix | Delete
}
[457] Fix | Delete
return $content;
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
/**
[461] Fix | Delete
* Swap post_content_filtered and post_content for editing
[462] Fix | Delete
*
[463] Fix | Delete
* @param string $content Post content_filtered.
[464] Fix | Delete
* @param int $id post ID.
[465] Fix | Delete
* @return string Swapped content
[466] Fix | Delete
*/
[467] Fix | Delete
public function edit_post_content_filtered( $content, $id ) {
[468] Fix | Delete
// if markdown was disabled, let's turn this off.
[469] Fix | Delete
if ( ! $this->is_posting_enabled() && $this->is_markdown( $id ) ) {
[470] Fix | Delete
$post = get_post( $id );
[471] Fix | Delete
if ( $post && ! empty( $post->post_content_filtered ) ) {
[472] Fix | Delete
$content = '';
[473] Fix | Delete
}
[474] Fix | Delete
}
[475] Fix | Delete
return $content;
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
/**
[479] Fix | Delete
* Some tags are allowed to have a 'markdown' attribute, allowing them to contain Markdown.
[480] Fix | Delete
* We need to tell KSES about those tags.
[481] Fix | Delete
*
[482] Fix | Delete
* @param array $tags List of tags that KSES allows.
[483] Fix | Delete
* @param string $context The context that KSES is allowing these tags.
[484] Fix | Delete
* @return array The tags that KSES allows, with our extra 'markdown' parameter where necessary.
[485] Fix | Delete
*/
[486] Fix | Delete
public function wp_kses_allowed_html( $tags, $context ) {
[487] Fix | Delete
if ( 'post' !== $context ) {
[488] Fix | Delete
return $tags;
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
$re = '/' . $this->get_parser()->contain_span_tags_re . '/';
[492] Fix | Delete
foreach ( $tags as $tag => $attributes ) {
[493] Fix | Delete
[494] Fix | Delete
// In case other filters have changed the value to a non-array, we skip it.
[495] Fix | Delete
if ( ! is_array( $attributes ) ) {
[496] Fix | Delete
continue;
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function