Making WordPress.org

Changeset 10237


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

WordPress.org Learn: Sync with GitHub

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

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
71 added
3 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/mu-plugins

    • Property svn:ignore set to
      0-sandbox.php
  • sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/locales.php

    r8347 r10237  
    1212namespace WordPressdotorg\Locales {
    1313
    14         use GP_Locales;
     14        use GP_Locales, GP_Locale;
    1515
    1616        /**
     
    2929        }
    3030        add_filter( 'get_available_languages', __NAMESPACE__ . '\set_available_languages', 10, 0 );
     31
     32        /**
     33         * Retrieves all available locales.
     34         *
     35         * @return GP_Locale[] Array of locale objects.
     36         */
     37        function get_locales() {
     38                wp_cache_add_global_groups( array( 'locale-associations' ) );
     39
     40                $wp_locales = wp_cache_get( 'locale-list', 'locale-associations' );
     41                if ( false === $wp_locales ) {
     42                        $wp_locales = (array) $GLOBALS['wpdb']->get_col( 'SELECT locale FROM wporg_locales' );
     43                        wp_cache_set( 'locale-list', $wp_locales, 'locale-associations' );
     44                }
     45
     46                $wp_locales[] = 'en_US';
     47                $locales = array();
     48
     49                foreach ( $wp_locales as $locale ) {
     50                        $gp_locale = GP_Locales::by_field( 'wp_locale', $locale );
     51                        if ( ! $gp_locale ) {
     52                                continue;
     53                        }
     54
     55                        $locales[ $locale ] = $gp_locale;
     56                }
     57
     58                natsort( $locales );
     59
     60                return $locales;
     61        }
     62
     63        /**
     64         * Get an array of locales with the locale code as key and the native name as value.
     65         *
     66         * @return array
     67         */
     68        function get_locales_with_native_names() {
     69                $locales = get_locales();
     70
     71                return wp_list_pluck( $locales, 'native_name', 'wp_locale' );
     72        }
     73
     74        /**
     75         * Get an array of locales with the locale code as key and the English name as value.
     76         *
     77         * @return array
     78         */
     79        function get_locales_with_english_names() {
     80                $locales = get_locales();
     81
     82                return wp_list_pluck( $locales, 'english_name', 'wp_locale' );
     83        }
    3184}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/blocks.php

    r10169 r10237  
    33namespace WPOrg_Learn\Blocks;
    44
     5use Error;
    56use function WPOrg_Learn\Post_Meta\get_workshop_duration;
    67
    78defined( 'WPINC' ) || die();
     9
     10/**
     11 * Actions and filters.
     12 */
     13add_action( 'init', __NAMESPACE__ . '\workshop_details_init' );
     14add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_block_style_assets' );
     15add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_block_style_assets' );
    816
    917/**
  • 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}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php

    r10169 r10237  
    77
    88defined( 'WPINC' ) || die();
     9
     10/**
     11 * Actions and filters.
     12 */
     13add_action( 'init', __NAMESPACE__ . '\register' );
     14add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_workshop_metaboxes' );
     15add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields', 10, 2 );
    916
    1017/**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-type.php

    r10202 r10237  
    44
    55defined( 'WPINC' ) || die();
     6
     7/**
     8 * Actions and filters.
     9 */
     10add_action( 'init', __NAMESPACE__ . '\register' );
    611
    712/**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/taxonomy.php

    r10202 r10237  
    44
    55defined( 'WPINC' ) || die();
     6
     7/**
     8 * Actions and filters.
     9 */
     10add_action( 'init', __NAMESPACE__ . '\register' );
    611
    712/**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/package.json

    r10169 r10237  
    1010                "build": "wp-scripts build",
    1111                "format:js": "wp-scripts format-js js",
    12                 "lint:css": "wp-scripts lint-style",
     12                "lint:css": "wp-scripts lint-style './**/*.{css,scss}' '!3rd-party'",
    1313                "lint:js": "wp-scripts lint-js js",
    1414                "packages-update": "wp-scripts packages-update"
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/wporg-learn.php

    r10202 r10237  
    99 */
    1010
    11 require_once dirname( __FILE__ ) . '/inc/class-shortcodes.php';
    12 require_once dirname( __FILE__ ) . '/inc/class-lesson-plan.php';
    13 require_once dirname( __FILE__ ) . '/inc/blocks.php';
    14 require_once dirname( __FILE__ ) . '/inc/post-meta.php';
    15 require_once dirname( __FILE__ ) . '/inc/post-type.php';
    16 require_once dirname( __FILE__ ) . '/inc/taxonomy.php';
     11namespace WPOrg_Learn;
     12
     13defined( 'WPINC' ) || die();
     14
     15define( __NAMESPACE__ . '\PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
     16define( __NAMESPACE__ . '\PLUGIN_URL', plugins_url( '/', __FILE__ ) );
    1717
    1818/**
    19  * Registry of actions and filters
     19 * Actions and filters.
    2020 */
    21 add_action( 'init', 'WPORG_Learn\Post_Type\register' );
    22 add_action( 'init', 'WPORG_Learn\Post_Meta\register' );
    23 add_action( 'init', 'WPORG_Learn\Taxonomy\register' );
    24 add_action( 'init', array( 'WPOrg_Learn\Shortcodes', 'action_init' ) );
    25 add_filter( 'the_title', array( 'WPOrg_Learn\Lesson_Plan', 'filter_the_title_edit_link' ), 10, 2 );
    26 add_filter( 'get_edit_post_link', array( 'WPOrg_Learn\Lesson_Plan', 'redirect_edit_link_to_github' ), 10, 3 );
    27 add_filter( 'o2_filter_post_actions', array( 'WPOrg_Learn\Lesson_Plan', 'redirect_o2_edit_link_to_github' ), 11, 2 );
    28 add_filter( 'the_content', array( 'WPORG_Learn\Lesson_Plan', 'replace_image_links' ) );
    29 
    30 add_action( 'init', 'WPORG_Learn\Blocks\workshop_details_init' );
    31 add_action( 'enqueue_block_editor_assets', 'WPORG_Learn\Blocks\enqueue_block_style_assets' );
    32 add_action( 'wp_enqueue_scripts', 'WPORG_Learn\Blocks\enqueue_block_style_assets' );
    33 add_action( 'add_meta_boxes', 'WPORG_Learn\Post_Meta\add_workshop_metaboxes' );
    34 add_action( 'save_post_wporg_workshop', 'WPORG_Learn\Post_Meta\save_workshop_metabox_fields', 10, 2 );
    35 add_filter( 'excerpt_length', 'theme_slug_excerpt_length', 999 );
    36 
    37 require_once dirname( __FILE__ ) . '/inc/class-markdown-import.php';
    38 /**
    39  * Markdown Import
    40  *
    41  * This functionality has been disabled as of 2020-08-12. All of the lesson plans have been imported
    42  * to learn.wordpress.org and can be updated via the WP admin interface. Leaving this here for now
    43  * in case we need to re-activate for some reason.
    44  *
    45 add_action( 'init', array( 'WPOrg_Learn\Markdown_Import', 'action_init' ) );
    46 add_action( 'wporg_learn_manifest_import', array( 'WPOrg_Learn\Markdown_Import', 'action_wporg_learn_manifest_import' ) );
    47 add_action( 'wporg_learn_markdown_import', array( 'WPOrg_Learn\Markdown_Import', 'action_wporg_learn_markdown_import' ) );
    48 add_action( 'load-post.php', array( 'WPOrg_Learn\Markdown_Import', 'action_load_post_php' ) );
    49 add_action( 'edit_form_after_title', array( 'WPOrg_Learn\Markdown_Import', 'action_edit_form_after_title' ) );
    50 add_action( 'save_post', array( 'WPOrg_Learn\Markdown_Import', 'action_save_post' ) );
    51 add_filter( 'cron_schedules', array( 'WPOrg_Learn\Markdown_Import', 'filter_cron_schedules' ) );
    52  */
     21add_action( 'plugins_loaded', __NAMESPACE__ . '\load_files' );
     22add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\register_thirdparty_assets', 9 );
     23add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_thirdparty_assets', 9 );
    5324
    5425/**
    55  * Filter the excerpt length to 50 words.
     26 * Shortcut to the includes directory.
    5627 *
    57  * @param int $length Excerpt length.
    58  * @return int (Maybe) modified excerpt length.
     28 * @return string
    5929 */
    60 function theme_slug_excerpt_length( $length ) {
    61         global $post;
    62 
    63         if ( is_admin() ) {
    64                 return $length;
    65         }
    66 
    67         if ( 'workshop' === $post->post_type ) {
    68                 return 35;
    69         }
    70 
    71         return 25;
     30function get_includes_path() {
     31        return plugin_dir_path( __FILE__ ) . 'inc/';
    7232}
    7333
    74 add_action( 'wp_head', function() {
    75         ?>
    76         <style>
    77                 pre code {
    78                         line-height: 16px;
    79                 }
    80                 a.github-edit {
    81                         margin-left: .5em;
    82                         font-size: .5em;
    83                         vertical-align: top;
    84                         display: inline-block;
    85                         border: 1px solid #eeeeee;
    86                         border-radius: 2px;
    87                         background: #eeeeee;
    88                         padding: .5em .6em .4em;
    89                         color: black;
    90                         margin-top: 0.1em;
    91                 }
    92                 a.github-edit > * {
    93                         opacity: 0.6;
    94                 }
    95                 a.github-edit:hover > * {
    96                         opacity: 1;
    97                         color: black;
    98                 }
    99                 a.github-edit img {
    100                         height: .8em;
    101                 }
    102                 .single-handbook div.table-of-contents {
    103                         margin: 0;
    104                         float: none;
    105                         padding: 0;
    106                         border: none;
    107                         box-shadow: none;
    108                         width: auto;
    109                 }
    110                 .single-handbook div.table-of-contents:after {
    111                         content: " ";
    112                         display: block;
    113                         clear: both;
    114                 }
    115                 .single-handbook .table-of-contents h2 {
    116                         display: none;
    117                 }
    118                 .single-handbook div.table-of-contents ul {
    119                         padding: 0;
    120                         margin-top: 0.4em;
    121                         margin-bottom: 1.1em;
    122                 }
    123                 .single-handbook div.table-of-contents > ul li {
    124                         display: inline-block;
    125                         padding: 0;
    126                         font-size: 12px;
    127                 }
    128                 .single-handbook div.table-of-contents > ul li a:after {
    129                         content: "|";
    130                         display: inline-block;
    131                         width: 20px;
    132                         text-align: center;
    133                         color: #eeeeee
    134                 }
    135                 .single-handbook div.table-of-contents > ul li:last-child a:after {
    136                         content: "";
    137                 }
    138                 .single-handbook div.table-of-contents ul ul {
    139                         display: none;
    140                 }
    141                 .single-handbook #secondary {
    142                         max-width: 240px;
    143                 }
    144         </style>
    145         <?php
    146 });
     34/**
     35 * Load the other PHP files for the plugin.
     36 *
     37 * @return void
     38 */
     39function load_files() {
     40        require_once get_includes_path() . 'blocks.php';
     41        require_once get_includes_path() . 'class-markdown-import.php';
     42        require_once get_includes_path() . 'post-meta.php';
     43        require_once get_includes_path() . 'post-type.php';
     44        require_once get_includes_path() . 'taxonomy.php';
     45}
     46
     47/**
     48 * Register scripts and styles for 3rd party libraries.
     49 *
     50 * @return void
     51 */
     52function register_thirdparty_assets() {
     53        wp_register_script(
     54                'select2',
     55                plugins_url( '/3rd-party/selectWoo/js/selectWoo.min.js', __FILE__ ),
     56                array( 'jquery' ),
     57                '1.0.8',
     58                true
     59        );
     60
     61        wp_register_style(
     62                'select2',
     63                plugins_url( '/3rd-party/selectWoo/css/selectWoo.min.css', __FILE__ ),
     64                array(),
     65                '1.0.8'
     66        );
     67}
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php

    r10202 r10237  
    199199        return get_post_meta( get_the_ID(), 'download_lesson_plan_slides_url', true );
    200200}
     201
     202/**
     203 * Modify the excerpt length for our custom post types.
     204 *
     205 * @param int $length Excerpt length.
     206 *
     207 * @return int (Maybe) modified excerpt length.
     208 */
     209function wporg_modify_excerpt_length( $length ) {
     210        if ( is_admin() ) {
     211                return $length;
     212        }
     213
     214        if ( 'wporg_workshop' === get_post_type() ) {
     215                return 35;
     216        }
     217
     218        return 25;
     219}
     220add_filter( 'excerpt_length', 'wporg_modify_excerpt_length', 999 );
    201221
    202222/**
Note: See TracChangeset for help on using the changeset viewer.