\WPCom_Markdown

Copyright (c) Automattic. All rights reserved.

Released under the GPL license http://www.opensource.org/licenses/gpl-license.php

This is an add-on for WordPress http://wordpress.org/


This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.


Summary

Methods
Properties
Constants
get_instance()
load()
maybe_load_actions_and_filters()
load_markdown_for_posts()
unload_markdown_for_posts()
add_o2_helpers()
o2_preview_post()
o2_preview_comment()
o2_escape_lists()
o2_unescape_lists()
preserve_code_blocks()
maybe_remove_kses()
register_setting()
sanitize_setting()
post_field()
comment_field()
is_posting_enabled()
is_commenting_enabled()
is_markdown()
add_default_post_type_support()
edit_post_content()
edit_post_content_filtered()
wp_insert_post_data()
wp_insert_post()
preprocess_comment()
comment_save_pre()
transform()
_wp_post_revision_fields()
wp_restore_post_revision()
xmlrpc_actions()
uncache_munged_posts()
make_filterable()
the_posts()
$posts_to_uncache
POST_OPTION
COMMENT_OPTION
POST_TYPE_SUPPORT
IS_MD_META
load_markdown_for_comments()
unload_markdown_for_comments()
get_support_url()
set_as_markdown()
get_parser()
get_post_screen_post_type()
comment_hash()
fix_latest_revision_on_restore()
check_for_mwgetpost()
swap_for_editing()
No protected properties found
N/A
prime_post_cache()
__construct()
$parser
$instance
$monitoring
N/A

Constants

POST_OPTION

POST_OPTION

COMMENT_OPTION

COMMENT_OPTION

POST_TYPE_SUPPORT

POST_TYPE_SUPPORT

IS_MD_META

IS_MD_META

Properties

$posts_to_uncache

$posts_to_uncache

$parser

$parser

$instance

$instance

$monitoring

$monitoring

Methods

get_instance()

get_instance() : object

Yay singletons!

Returns

object —

WPCom_Markdown instance

load()

load() : null

Kicks things off on `init` action

Returns

null

maybe_load_actions_and_filters()

maybe_load_actions_and_filters() : null

Called on init and fires on blog_switch to decide if our actions and filters should be running.

Returns

null

load_markdown_for_posts()

load_markdown_for_posts() : null

Set up hooks for enabling Markdown conversion on posts

Returns

null

unload_markdown_for_posts()

unload_markdown_for_posts() : null

Removes hooks to disable Markdown conversion on posts

Returns

null

add_o2_helpers()

add_o2_helpers() : null

o2 does some of what we do. Let's take precedence.

Returns

null

o2_preview_post()

o2_preview_post(string $text) : string

If Markdown is enabled for posts on this blog, filter the text for o2 previews

Parameters

string $text

Post text

Returns

string —

Post text transformed through the magic of Markdown

o2_preview_comment()

o2_preview_comment(string $text) : string

If Markdown is enabled for comments on this blog, filter the text for o2 previews

Parameters

string $text

Comment text

Returns

string —

Comment text transformed through the magic of Markdown

o2_escape_lists()

o2_escape_lists(string $text) : string

Escapes lists so that o2 doesn't trounce them

Parameters

string $text

Post/comment text

Returns

string —

Text escaped with HTML entity for asterisk

o2_unescape_lists()

o2_unescape_lists(string $text) : string

Unescapes the token we inserted on o2_escape_lists

Parameters

string $text

Post/comment text with HTML entities for asterisks

Returns

string —

Text with the HTML entity removed

preserve_code_blocks()

preserve_code_blocks(string $text) : string

Preserve code blocks from being munged by KSES before they have a chance

Parameters

string $text

post content

Returns

string —

post content with code blocks escaped

maybe_remove_kses()

maybe_remove_kses() : null

Remove KSES if it's there. Store the result to manually invoke later if needed.

Returns

null

register_setting()

register_setting() : null

Add our Writing and Discussion settings.

Returns

null

sanitize_setting()

sanitize_setting(string $input) : bool

Sanitize setting. Don't really want to store "on" value, so we'll store "1" instead!

Parameters

string $input

Value received by settings API via $_POST

Returns

bool —

Cast to boolean.

post_field()

post_field() : null

Prints HTML for the Writing setting

Returns

null

comment_field()

comment_field() : null

Prints HTML for the Discussion setting

Returns

null

is_posting_enabled()

is_posting_enabled() : boolean

Is Mardown conversion for posts enabled?

Returns

boolean

is_commenting_enabled()

is_commenting_enabled() : boolean

Is Markdown conversion for comments enabled?

Returns

boolean

is_markdown()

is_markdown(int $post_id) : boolean

Check if a $post_id has Markdown enabled

Parameters

int $post_id

A post ID.

Returns

boolean

add_default_post_type_support()

add_default_post_type_support() : null

We don't want Markdown conversion all over the place.

Returns

null

edit_post_content()

edit_post_content(string $content, int $id) : string

Swap post_content and post_content_filtered for editing

Parameters

string $content

Post content

int $id

post ID

Returns

string —

Swapped content

edit_post_content_filtered()

edit_post_content_filtered(string $content, int $id) : string

Swap post_content_filtered and post_content for editing

Parameters

string $content

Post content_filtered

int $id

post ID

Returns

string —

Swapped content

wp_insert_post_data()

wp_insert_post_data(array $post_data, array $postarr) : array

Magic happens here. Markdown is converted and stored on post_content. Original Markdown is stored in post_content_filtered so that we can continue editing as Markdown.

Parameters

array $post_data

The post data that will be inserted into the DB. Slashed.

array $postarr

All the stuff that was in $_POST.

Returns

array —

$post_data with post_content and post_content_filtered modified

wp_insert_post()

wp_insert_post(int $post_id) : null

Calls on wp_insert_post action, after wp_insert_post_data. This way we can still set postmeta on our revisions after it's all been deleted.

Parameters

int $post_id

The post ID that has just been added/updated

Returns

null

preprocess_comment()

preprocess_comment(string $comment_data) : string

Run a comment through Markdown. Easy peasy.

Parameters

string $comment_data

A comment.

Returns

string —

A comment, processed by Markdown.

comment_save_pre()

comment_save_pre( $content)

Parameters

$content

transform()

transform(string $text, array $args) : string

Markdown conversion. Some DRYness for repetitive tasks.

Parameters

string $text

Content to be run through Markdown

array $args

Arguments, with keys:

                  id: provide a string to prefix footnotes with a unique identifier
                  unslash: when true, expects and returns slashed data
                  decode_code_blocks: when true, assume that text in fenced code blocks is already
                    HTML encoded and should be decoded before being passed to Markdown, which does
                    its own encoding.

Returns

string —

Markdown-processed content

_wp_post_revision_fields()

_wp_post_revision_fields(array $fields) : array

Shows Markdown in the Revisions screen, and ensures that post_content_filtered is maintained on revisions

Parameters

array $fields

Post fields pertinent to revisions

Returns

array —

Modified array to include post_content_filtered

wp_restore_post_revision()

wp_restore_post_revision(int $post_id, int $revision_id) : null

Do some song and dance to keep all post_content and post_content_filtered content in the expected place when a post revision is restored.

Parameters

int $post_id

The post ID have a restore done to it

int $revision_id

The revision ID being restored

Returns

null

xmlrpc_actions()

xmlrpc_actions(string $xmlrpc_method) : null

Kicks off magic for an XML-RPC session. We want to keep editing Markdown and publishing HTML.

Parameters

string $xmlrpc_method

The current XML-RPC method

Returns

null

uncache_munged_posts()

uncache_munged_posts() : null

We munge the post cache to serve proper markdown content to XML-RPC clients.

Uncache these after the XML-RPC session ends.

Returns

null

make_filterable()

make_filterable(object $wp_query) : null

Since *.(get)?[Rr]ecentPosts calls get_posts with suppress filters on, we need to turn them back on so that we can swap things for editing.

Parameters

object $wp_query

WP_Query object

Returns

null

the_posts()

the_posts(array $posts, object $wp_query) : array

Swaps post_content and post_content_filtered for editing.

Parameters

array $posts

Posts returned by the just-completed query

object $wp_query

Current WP_Query object

Returns

array —

Modified $posts

load_markdown_for_comments()

load_markdown_for_comments() : null

Set up hooks for enabling Markdown conversion on comments

Returns

null

unload_markdown_for_comments()

unload_markdown_for_comments() : null

Removes hooks to disable Markdown conversion

Returns

null

get_support_url()

get_support_url() : string

Get the support url for Markdown

Returns

string —

support url

set_as_markdown()

set_as_markdown(int $post_id) : bool

Set Markdown as enabled on a post_id. We skip over update_postmeta so we can sneakily set metadata on post revisions, which we need.

Parameters

int $post_id

A post ID.

Returns

bool —

The metadata was successfully set.

get_parser()

get_parser() : object

Get our Markdown parser object, optionally requiring all of our needed classes and instantiating our parser.

Returns

object —

WPCom_GHF_Markdown_Parser instance.

get_post_screen_post_type()

get_post_screen_post_type() : string

Figure out the post type of the post screen we're on

Returns

string —

Current post_type

comment_hash()

comment_hash( $content)

Parameters

$content

fix_latest_revision_on_restore()

fix_latest_revision_on_restore(int $post_id) : null

We need to ensure the last revision has Markdown, not HTML in its post_content_filtered column after a restore.

Parameters

int $post_id

The post ID that was just restored.

Returns

null

check_for_mwgetpost()

check_for_mwgetpost() : null

The metaWeblog.getPost xmlrpc_call action fires *after* get_post() is called.

So, we have to detect that method and prime the post cache early.

Returns

null

swap_for_editing()

swap_for_editing(object $post) : object

Swaps `post_content_filtered` back to `post_content` for editing purposes.

Parameters

object $post

WP_Post object

Returns

object —

WP_Post object with swapped post_content_filtered and post_content

prime_post_cache()

prime_post_cache( $post_id) : null

Prime the post cache with swapped post_content. This is a sneaky way of getting around the fact that there are no good hooks to call on the *.getPost xmlrpc methods.

Parameters

$post_id

Returns

null

__construct()

__construct()

Singleton silence is golden