Changeset 1318959
- Timestamp:
- 12/31/2015 03:49:57 AM (10 years ago)
- Location:
- library/trunk
- Files:
-
- 5 edited
-
README.txt (modified) (2 diffs)
-
admin/class-library-admin.php (modified) (3 diffs)
-
languages/library.pot (modified) (3 diffs)
-
library.php (modified) (1 diff)
-
public/class-library.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
library/trunk/README.txt
r912797 r1318959 1 1 === Library === 2 Contributors: developdaly 2 Contributors: developdaly, mikemanger, adamkrawiec 3 3 Tags: strings, library, content, shortcodes, dictionary, wp-strings 4 4 Requires at least: 3.8.1 5 Tested up to: 3.9.16 Stable tag: 1. 0.25 Tested up to: 4.4 6 Stable tag: 1.1.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 60 60 == Changelog == 61 61 62 = 1.1.0 = 63 * Adds a media button to easily insert shortcodes 64 * Improved error handling 65 62 66 = 1.0.2 = 63 67 * Localized admin screen strings -
library/trunk/admin/class-library-admin.php
r912797 r1318959 51 51 $this->plugin_slug = $plugin->get_plugin_slug(); 52 52 53 add_action( 'init', array( $this, 'register' ) );53 add_action( 'init', array( $this, 'register' ), 11 ); 54 54 55 55 /* Fire our meta box setup function on the post editor screen. */ 56 56 add_action( 'load-post.php', array( $this, 'library_meta_boxes_setup' ) ); 57 58 add_action( 'media_buttons', array( $this, 'add_form_button' ), 20 ); 59 60 add_action( 'admin_footer', array( $this, 'add_mce_popup' ), 11 ); 57 61 58 62 } … … 78 82 79 83 $labels = array( 80 'name' => _x( 'Terms', ' library_term' ),81 'singular_name' => _x( 'Term', ' library_term' ),82 'add_new' => _x( 'Add New', ' library_term' ),83 'add_new_item' => _ x( 'Add New Term', 'library_term' ),84 'edit_item' => _ x( 'Edit Term', 'library_term' ),85 'new_item' => _ x( 'New Term', 'library_term' ),86 'view_item' => _ x( 'View Term', 'library_term' ),87 'search_items' => _ x( 'Search Terms', 'library_term' ),88 'not_found' => _ x( 'No terms found', 'library_term' ),89 'not_found_in_trash' => _ x( 'No terms found in Trash', 'library_term' ),90 'parent_item_colon' => _ x( 'Parent Term:', 'library_term' ),91 'menu_name' => _x( 'Library', ' library_term' ),84 'name' => _x( 'Terms', 'shortcode terms general name', 'library' ), 85 'singular_name' => _x( 'Term', 'shortcode term singular name', 'library' ), 86 'add_new' => _x( 'Add New', 'shortcode term', 'library' ), 87 'add_new_item' => __( 'Add New Term', 'library' ), 88 'edit_item' => __( 'Edit Term', 'library' ), 89 'new_item' => __( 'New Term', 'library' ), 90 'view_item' => __( 'View Term', 'library' ), 91 'search_items' => __( 'Search Terms', 'library' ), 92 'not_found' => __( 'No terms found', 'library' ), 93 'not_found_in_trash' => __( 'No terms found in Trash', 'library' ), 94 'parent_item_colon' => __( 'Parent Term:', 'library' ), 95 'menu_name' => _x( 'Library', 'shortcode term collection', 'library' ), 92 96 ); 93 97 94 98 $args = array( 95 99 'labels' => $labels, 96 'hierarchical' => false,97 100 'supports' => array( 'title', 'editor', 'revisions' ), 98 'public' => true,99 'show_ui' => true, 100 'show_in_ menu' => true,101 'public' => false, // hide the front end UI 102 'show_ui' => true, // keep admin UI 103 'show_in_nav_menus' => true, 101 104 'menu_position' => 5, 102 'show_in_nav_menus' => true,103 'publicly_queryable' => true,104 'exclude_from_search' => false,105 'has_archive' => true,106 'query_var' => true,107 'can_export' => true,108 'rewrite' => true,109 'capability_type' => 'post'110 105 ); 111 106 … … 149 144 global $post; 150 145 151 echo esc_html( _e( '<p>To display this inside your content use <code>[library term="'. $post->post_name .'"]</code> OR to use this inside of a template file use <code><?php echo do_shortcode(\'[library term="'. $post->post_name .'"]\') ?></code></p>', 'library' ) ); 152 echo esc_html( _e( '<p>You can change the term slug by editing the permalink slug underneath the title.</p>', 'library' ) ); 153 154 } 146 $shortcode_example = '<code>[library term="' . $post->post_name . '"]</code>'; 147 $php_example = '<code><?php echo do_shortcode( \'[library term="' . $post->post_name . '"]\' ) ?></code>'; 148 echo '<p>'; 149 printf( __( 'To display this inside your content use %s OR to use this inside of a template file use %s', 'library' ), $shortcode_example, $php_example ); 150 echo '</p><p>'; 151 _e( 'You can change the term slug by editing the permalink slug underneath the title.', 'library' ); 152 echo '</p>'; 153 154 } 155 156 /** 157 * Checks to see if we are editing or adding a post. 158 * 159 * @return bool 160 * @since 1.0.3 161 */ 162 public static function page_supports_add_form_button() { 163 // check we aren't calling this too early 164 if ( ! function_exists( 'get_current_screen' ) ) { 165 return false; 166 } 167 168 $screen = get_current_screen(); 169 $is_post_edit_page = in_array( $screen->parent_base, array( 'edit' ) ); 170 171 if ( 'library_term' == $screen->post_type ) { 172 $is_post_edit_page = false; 173 } 174 175 $display_add_form_button = apply_filters( 'library_display_add_form_button', $is_post_edit_page ); 176 177 return $display_add_form_button; 178 } 179 180 /** 181 * Adds a button to the editor 182 * 183 * @since 1.0.3 184 */ 185 public function add_form_button() { 186 $is_add_form_page = self::page_supports_add_form_button(); 187 if ( ! $is_add_form_page ) { 188 return; 189 } 190 191 // do a version check for the new 3.5 UI 192 $version = get_bloginfo( 'version' ); 193 194 if ( $version < 3.5 ) { 195 // show button for v 3.4 and below 196 echo '<a href="#TB_inline?width=480&inlineId=select_library_shortcode" class="thickbox" id="add_gform">' . __( 'Add Library Shortcode', 'library' ) . '</a>'; 197 } else { 198 // display button matching new UI 199 echo '<a href="#TB_inline?width=480&inlineId=select_library_shortcode" class="thickbox button library_media_link" id="add_library_shortcode" title="' . __( 'Add Library Shortcode', 'library' ) . '">' . __( 'Add Library Shortcode', 'library' ) . '</a>'; 200 } 201 } 202 203 /** 204 * Add the form for inserting shortcodes into posts 205 * 206 * @since 1.0.3 207 */ 208 public static function add_mce_popup() { 209 if ( ! self::page_supports_add_form_button() ) { 210 return; 211 } 212 ?> 213 <script> 214 function library_insert_shortcode() { 215 var term_slug = jQuery( '#add_term_slug' ).val(); 216 if ( '' === term_slug ) { 217 alert( '<?php _e( 'Please select a shortcode', 'library' ); ?>' ); 218 return; 219 } 220 221 window.send_to_editor( '[library term="' + term_slug + '"]' ); 222 } 223 </script> 224 225 <div id="select_library_shortcode" style="display:none;"> 226 <div class="wrap"> 227 <h3><?php _e( 'Insert A Shortcode', 'library' ); ?></h3> 228 <p> 229 <?php _e( 'Select a term below to add it to your post or page.', 'library' ); ?> 230 </p> 231 <p> 232 <select id="add_term_slug"> 233 <option value=""><?php _e( 'Select a Term', 'library' ); ?></option> 234 <?php 235 // TODO: what happens when there are 1000 terms? AJAX list with a short fallback 236 $args = array( 237 'post_type' => 'library_term', 238 'order' => 'ASC', 239 'orderby' => 'title', 240 'posts_per_page' => 200, 241 'no_found_rows' => true, 242 ); 243 $query = new WP_Query( $args ); 244 245 if ( $query->have_posts() ) { 246 global $post; 247 while ( $query->have_posts() ) { 248 $query->the_post(); 249 ?> 250 <option value="<?php echo esc_attr( $post->post_name ); ?>"><?php the_title(); ?></option> 251 <?php 252 } 253 } 254 wp_reset_postdata(); 255 ?> 256 </select> <br/> 257 </p> 258 <p> 259 <input type="button" class="button button-primary" value="<?php esc_attr_e( 'Insert Shortcode', 'library' ); ?>" onclick="library_insert_shortcode();"/> 260 <a class="button" onclick="tb_remove(); return false;"><?php esc_attr_e( 'Cancel', 'library' ); ?></a> 261 </p> 262 </div> 263 </div> 264 265 <?php 266 } 267 155 268 156 269 } -
library/trunk/languages/library.pot
r873050 r1318959 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: 1.0. 1\n"5 "Project-Id-Version: 1.0.3\n" 6 6 "Report-Msgid-Bugs-To: http://wordpress.org/plugins/library\n" 7 "POT-Creation-Date: 2014- 03-10 15:30-0600\n"8 "PO-Revision-Date: 2014- 03-10 15:30-0600\n"9 "Last-Translator: Patrick Daly <patrick@developdaly.com>\n"7 "POT-Creation-Date: 2014-11-28 10:59-0000\n" 8 "PO-Revision-Date: 2014-11-28 10:59-0000\n" 9 "Last-Translator: Mike Manger <mike.manger@lighthouseuk.net>\n" 10 10 "Language-Team: Develop Daly <patrick@developdaly.com>\n" 11 11 "Language: en_US\n" … … 13 13 "Content-Type: text/plain; charset=UTF-8\n" 14 14 "Content-Transfer-Encoding: 8bit\n" 15 "X-Generator: Poedit 1.6. 4\n"15 "X-Generator: Poedit 1.6.10\n" 16 16 "X-Poedit-KeywordsList: __;_e;_n;_x;esc_html_e;esc_html__;esc_attr_e;" 17 17 "esc_attr__;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;_x:1,2c;_n:1,2\n" … … 20 20 "X-Poedit-SearchPath-0: .\n" 21 21 22 #: admin/class-library-admin.php:8 023 msgctxt " library_term"22 #: admin/class-library-admin.php:84 23 msgctxt "shortcode terms general name" 24 24 msgid "Terms" 25 msgstr "Terms" 26 27 #: admin/class-library-admin.php:81 28 msgctxt "library_term" 29 msgid "Term" 30 msgstr "Term" 31 32 #: admin/class-library-admin.php:82 33 msgctxt "library_term" 34 msgid "Add New" 35 msgstr "Add New" 36 37 #: admin/class-library-admin.php:83 38 msgctxt "library_term" 39 msgid "Add New Term" 40 msgstr "Add New Term" 41 42 #: admin/class-library-admin.php:84 43 msgctxt "library_term" 44 msgid "Edit Term" 45 msgstr "Edit Term" 25 msgstr "" 46 26 47 27 #: admin/class-library-admin.php:85 48 msgctxt " library_term"49 msgid " NewTerm"50 msgstr " New Term"28 msgctxt "shortcode term singular name" 29 msgid "Term" 30 msgstr "" 51 31 52 32 #: admin/class-library-admin.php:86 53 msgctxt " library_term"54 msgid " View Term"55 msgstr " View Term"33 msgctxt "shortcode term" 34 msgid "Add New" 35 msgstr "" 56 36 57 37 #: admin/class-library-admin.php:87 58 msgctxt "library_term" 59 msgid "Search Terms" 60 msgstr "Search Terms" 38 msgid "Add New Term" 39 msgstr "" 61 40 62 41 #: admin/class-library-admin.php:88 63 msgctxt "library_term" 64 msgid "No terms found" 65 msgstr "Not terms found" 42 msgid "Edit Term" 43 msgstr "" 66 44 67 45 #: admin/class-library-admin.php:89 68 msgctxt "library_term" 69 msgid "No terms found in Trash" 70 msgstr "No terms found in Trash" 46 msgid "New Term" 47 msgstr "" 71 48 72 49 #: admin/class-library-admin.php:90 73 msgctxt "library_term" 74 msgid "Parent Term:" 75 msgstr "Parent Term:" 50 msgid "View Term" 51 msgstr "" 76 52 77 53 #: admin/class-library-admin.php:91 78 msgctxt "library_term" 54 msgid "Search Terms" 55 msgstr "" 56 57 #: admin/class-library-admin.php:92 58 msgid "No terms found" 59 msgstr "" 60 61 #: admin/class-library-admin.php:93 62 msgid "No terms found in Trash" 63 msgstr "" 64 65 #: admin/class-library-admin.php:94 66 msgid "Parent Term:" 67 msgstr "" 68 69 #: admin/class-library-admin.php:95 70 msgctxt "shortcode term collection" 79 71 msgid "Library" 80 msgstr " LIbrary"72 msgstr "" 81 73 82 #: admin/class-library-admin.php:13 574 #: admin/class-library-admin.php:130 83 75 msgid "How to Use this Term" 84 msgstr "How to Use this Term" 76 msgstr "" 77 78 #: admin/class-library-admin.php:149 79 #, php-format 80 msgid "" 81 "To display this inside your content use %s OR to use this inside of a " 82 "template file use %s" 83 msgstr "" 84 85 #: admin/class-library-admin.php:151 86 msgid "" 87 "You can change the term slug by editing the permalink slug underneath the " 88 "title." 89 msgstr "" 90 91 #: admin/class-library-admin.php:196 admin/class-library-admin.php:199 92 msgid "Add Library Shortcode" 93 msgstr "" 94 95 #: admin/class-library-admin.php:217 96 msgid "Please select a shortcode" 97 msgstr "" 98 99 #: admin/class-library-admin.php:227 100 msgid "Insert A Shortcode" 101 msgstr "" 102 103 #: admin/class-library-admin.php:229 104 msgid "Select a term below to add it to your post or page." 105 msgstr "" 106 107 #: admin/class-library-admin.php:233 108 msgid "Select a Term" 109 msgstr "" 110 111 #: admin/class-library-admin.php:257 112 msgid "Insert Shortcode" 113 msgstr "" 114 115 #: admin/class-library-admin.php:258 116 msgid "Cancel" 117 msgstr "" -
library/trunk/library.php
r912797 r1318959 16 16 * Plugin URI: http://wordpress.org/plugins/library 17 17 * Description: Create a library of reusable terms (strings) and display their contents anywhere on your site with a shortcode. 18 * Version: 1. 0.218 * Version: 1.1.0 19 19 * Author: Patrick Daly 20 20 * Author URI: http://developdaly.com -
library/trunk/public/class-library.php
r873050 r1318959 29 29 * @var string 30 30 */ 31 const VERSION = '1. 0.0';31 const VERSION = '1.1.0'; 32 32 33 33 /** … … 65 65 // Load plugin text domain 66 66 add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); 67 67 68 68 // Add the library shortcode 69 69 add_shortcode( 'library', array( $this, 'shortcode' ) ); … … 98 98 return self::$instance; 99 99 } 100 100 101 101 /** 102 102 * Load the plugin text domain for translation. … … 110 110 111 111 load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' ); 112 load_plugin_textdomain( $domain, FALSE, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' );112 load_plugin_textdomain( $domain, false, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' ); 113 113 114 114 } … … 121 121 public function shortcode( $atts ) { 122 122 global $post; 123 123 124 124 $args = array( 125 125 'name' => $atts['term'], 126 'post_type' => 'library_term' 126 'post_type' => 'library_term', 127 127 ); 128 128 129 129 $query = new WP_Query( $args ); 130 131 $output = ''; 130 132 131 133 if ( $query->have_posts() ) { … … 137 139 138 140 wp_reset_postdata(); 139 141 140 142 return $output; 141 143 }
Note: See TracChangeset
for help on using the changeset viewer.