Making WordPress.org


Ignore:
Timestamp:
09/03/2020 11:57:12 PM (4 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/compare/fcab3279c24740fb625278be5fd3484157df8941...81fc947c7f4f4174ef30a2f6c9fc42d3608e5a49

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/class-markdown-import.php

    r10169 r10237  
    11<?php
     2/**
     3 * Markdown Import
     4 *
     5 * This functionality has been disabled as of 2020-08-12. All of the lesson plans have been imported
     6 * to learn.wordpress.org and can be updated via the WP admin interface. Leaving this here for now
     7 * in case we need to re-activate for some reason.
     8 */
    29
    310namespace WPOrg_Learn;
    411
    5 use WP_Error;
    6 use WP_Query;
    7 
     12use WP_Error, WP_Query;
     13
     14// These actions/filters should not be added while markdown import is disabled.
     15//add_action( 'init', array( 'WPOrg_Learn\Markdown_Import', 'action_init' ) );
     16//add_action( 'wporg_learn_manifest_import', array( 'WPOrg_Learn\Markdown_Import', 'action_wporg_learn_manifest_import' ) );
     17//add_action( 'wporg_learn_markdown_import', array( 'WPOrg_Learn\Markdown_Import', 'action_wporg_learn_markdown_import' ) );
     18//add_action( 'load-post.php', array( 'WPOrg_Learn\Markdown_Import', 'action_load_post_php' ) );
     19//add_action( 'edit_form_after_title', array( 'WPOrg_Learn\Markdown_Import', 'action_edit_form_after_title' ) );
     20//add_action( 'save_post', array( 'WPOrg_Learn\Markdown_Import', 'action_save_post' ) );
     21//add_filter( 'cron_schedules', array( 'WPOrg_Learn\Markdown_Import', 'filter_cron_schedules' ) );
     22
     23// This filter is still necessary because the lesson plans that were originally imported from GitHub still require
     24// that image assets be loaded from the same repositories.
     25add_filter( 'the_content', array( 'WPOrg_Learn\Markdown_Import', 'replace_image_links' ) );
     26
     27/**
     28 * Class Markdown_Import
     29 *
     30 * @package WPOrg_Learn
     31 */
    832class Markdown_Import {
    933
     
    184208            placeholder="Enter a URL representing a markdown file to import"
    185209            size="50" />
    186         </label> 
     210        </label>
    187211        <?php
    188212        if ( $markdown_source ) :
     
    319343        return $html;
    320344    }
     345
     346    /**
     347     * Source images from the GitHub repo.
     348     *
     349     * @param string $content
     350     *
     351     * @return string|string[]
     352     */
     353    public static function replace_image_links( $content ) {
     354        $post_id         = get_the_ID();
     355        $markdown_source = self::get_markdown_source( $post_id );
     356        if ( is_wp_error( $markdown_source ) ) {
     357            return $content;
     358        }
     359        $markdown_source = str_replace( '/README.md', '', $markdown_source );
     360        $content         = str_replace( '<img src="/images/', '<img src="' . $markdown_source . '/images/', $content );
     361
     362        return $content;
     363    }
    321364}
Note: See TracChangeset for help on using the changeset viewer.