Making WordPress.org


Ignore:
Timestamp:
05/30/2017 10:47:04 PM (8 years ago)
Author:
danielbachhuber
Message:

make/cli: Create a shortcode for listing issues

See https://github.com/wp-cli/wp-cli/issues/4045

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/p2-new-post-categories/p2-new-post-categories.php

    r118 r5526  
    22/*
    33Plugin Name: P2 New Post Categories
    4 Description: Adds a category dropdown to P2s new post form.
    5 Version:     0.2
     4Plugin URI:  http://wordpress.org/plugins/p2-new-post-categories
     5Description: Adds a category dropdown to P2's new post form.
     6Version:     0.3
     7Author:      Ian Dunn
     8Author URI:  http://iandunn.name
    69License:     GPLv2 or Later
    710*/
    811
    9 /*
    10  * Note: This has been forked from the original version to conform to WordPress.org conventions.
    11  */
    12 
    13 
    1412class P2NewPostCategories {
    15     const VERSION = '0.2';
     13    const VERSION = '0.3';
    1614
    1715    /*
     
    1917     */
    2018    public function __construct() {
    21         add_action( 'wp_head',                              array( $this, 'print_css' ) );
    22         add_action( 'wp_footer',                            array( $this, 'print_javascript' ) );
    23 
     19        add_action( 'admin_notices',                        array( $this, 'check_dependencies' ) );
     20        add_action( 'wp_enqueue_scripts',                   array( $this, 'enqueue_scripts' ) );
    2421        add_action( 'p2_post_form',                         array( $this, 'add_new_post_category_dropdown' ) );
    2522        add_action( 'wp_ajax_p2npc_assign_category',        array( $this, 'assign_category_to_post' ) );
     
    2724    }
    2825
     26    /**
     27     * The p2_new_post_submit_success trigger wasn't added until p2 1.5.2 and we can't work without it. 
     28     */
     29    public function check_dependencies() {
     30        $current_theme = wp_get_theme();
     31        $parent_theme  = $current_theme->parent();
     32        if ( ! $parent_theme ) {
     33            $parent_theme = $current_theme;
     34        }
     35       
     36        if ( 'P2' != $parent_theme->get( 'Name' ) || version_compare( $parent_theme->get( 'Version' ), '1.5.2', '<' ) ) {
     37            echo '<div class="error">P2 New Post Categories requires p2 version 1.5.2 or above in order to work.</div>';
     38        }
     39    }
     40   
    2941    /*
    30      * Print our CSS
     42     * Enqueue our scripts and styles
    3143     */
    32     public function print_css() {
    33         ?>
     44    public function enqueue_scripts() {
     45        wp_register_script(
     46            'P2NewPostCategories',
     47            plugins_url( 'functions.js', __FILE__ ),
     48            array( 'jquery', ),
     49            self::VERSION,
     50            true
     51        );
    3452
    35         <!-- Begin P2 New Post Categories -->
    36         <style type="text/css">
    37             #new_post {
    38                 position: relative;
    39                 padding-bottom: 2.25em;
    40             }
     53        wp_register_style(
     54            'P2NewPostCategories',
     55            plugins_url( 'style.css', __FILE__ ),
     56            array(),
     57            self::VERSION
     58        );
    4159
    42             #p2-new-post-category {
    43                 position: absolute;
    44                 left: 0;
    45                 bottom: 0;
    46             }
    47         </style>
    48         <!-- End P2 New Post Categories -->
    49 
    50         <?php
    51     }
    52 
    53     /*
    54      * Print our JavaScript
    55      */
    56     public function print_javascript() {
    57         ?>
    58 
    59         <!-- Begin P2 New Post Categories -->
    60         <script type="text/javascript">
    61             ( function( $ ) {
    62 
    63                 var P2NewPostCategories = {
    64 
    65                     /*
    66                      * Initialization
    67                      */
    68                     construct : function() {
    69                         P2NewPostCategories.dropdown         = $( '#p2-new-post-category' );
    70                         P2NewPostCategories.dropdown_default = P2NewPostCategories.dropdown.val();
    71 
    72                         $( document ).on( 'p2_new_post_submit_success', P2NewPostCategories.new_post );
    73                     },
    74 
    75                     /**
    76                      * Assign the selected category to the new post
    77                      * @param object event
    78                      * @param object data
    79                      */
    80                     new_post : function( event, data ) {
    81                         $.post(
    82                             ajaxUrl.replace( '?p2ajax=true', '' ), {
    83                                 'action'                      : 'p2npc_assign_category',
    84                                 'post_id'                     : parseInt( data.post_id ),
    85                                 'category_id'                 : parseInt( P2NewPostCategories.dropdown.val() ),
    86                                 'p2npc_assign_category_nonce' : $( '#p2npc_assign_category_nonce' ).val()
    87                             }
    88                         );
    89 
    90                         P2NewPostCategories.dropdown.val( parseInt( P2NewPostCategories.dropdown_default ) ).change();
    91                     }
    92                 };
    93 
    94                 P2NewPostCategories.construct();
    95 
    96             } )( jQuery );
    97         </script>
    98         <!-- End P2 New Post Categories -->
    99 
    100         <?php
     60        wp_enqueue_script( 'P2NewPostCategories' );
     61        wp_enqueue_style( 'P2NewPostCategories' );
    10162    }
    10263
Note: See TracChangeset for help on using the changeset viewer.