Changeset 5526 for sites/trunk/wordpress.org/public_html/wp-content/plugins/p2-new-post-categories/p2-new-post-categories.php
- Timestamp:
- 05/30/2017 10:47:04 PM (8 years ago)
- 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 2 2 /* 3 3 Plugin Name: P2 New Post Categories 4 Description: Adds a category dropdown to P2s new post form. 5 Version: 0.2 4 Plugin URI: http://wordpress.org/plugins/p2-new-post-categories 5 Description: Adds a category dropdown to P2's new post form. 6 Version: 0.3 7 Author: Ian Dunn 8 Author URI: http://iandunn.name 6 9 License: GPLv2 or Later 7 10 */ 8 11 9 /*10 * Note: This has been forked from the original version to conform to WordPress.org conventions.11 */12 13 14 12 class P2NewPostCategories { 15 const VERSION = '0. 2';13 const VERSION = '0.3'; 16 14 17 15 /* … … 19 17 */ 20 18 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' ) ); 24 21 add_action( 'p2_post_form', array( $this, 'add_new_post_category_dropdown' ) ); 25 22 add_action( 'wp_ajax_p2npc_assign_category', array( $this, 'assign_category_to_post' ) ); … … 27 24 } 28 25 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 29 41 /* 30 * Print our CSS42 * Enqueue our scripts and styles 31 43 */ 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 ); 34 52 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 ); 41 59 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' ); 101 62 } 102 63
Note: See TracChangeset
for help on using the changeset viewer.