Changeset 1314584
- Timestamp:
- 12/22/2015 09:51:52 PM (10 years ago)
- Location:
- wp-order-by/trunk
- Files:
-
- 1 added
- 5 edited
-
admin-options.php (modified) (12 diffs)
-
css/wpob.css (modified) (1 diff)
-
readme.txt (modified) (4 diffs)
-
views/form_elements.php (modified) (1 diff)
-
views/form_extra.php (added)
-
wp-order-by.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-order-by/trunk/admin-options.php
r1302126 r1314584 7 7 if ( is_admin() ){ 8 8 load_plugin_textdomain('wp-order-by', false, basename( dirname( __FILE__ ) ) . '/lang' ); 9 10 9 //register and enqueue plugin scripts and styles 11 10 add_action( 'admin_init', array( $this, 'register_plugin_styles' ) ); … … 36 35 ); 37 36 38 private function get_all_public_post_types_names() {37 private static function get_all_public_post_types_names() { 39 38 $args = array( 40 39 'public' => true … … 55 54 else echo '<div id="user_message" class="error"><p><strong>'.$this->data["err_message"].'</strong></p></div>'; 56 55 } 56 } 57 58 private static function get_admin_screen_current_post_type() { 59 $screen = get_current_screen(); 60 $pt = $screen->post_type; 61 if($pt=='') { 62 if($screen->parent_file == 'edit.php') 63 $pt = 'post'; 64 } 65 return $pt; 66 } 67 68 private static function draw_posts_select_box($type = '', $select_default_text='', $post_ids) { 69 70 $post_type = WpobPlugin::get_admin_screen_current_post_type(); 71 $posts = WpobPlugin::get_all_posts_of_current_post_type(); 72 $selected_default = ''; 73 if( WpobPlugin::is_no_exclude_ids_of_post_type($post_type, $post_ids) ) $selected_default = ' selected '; 74 echo '<select id="posts_select_box" name="wpob-exclude-posts[]" class="posts_select_box" '.$type.'>'; 75 if( !empty($select_default_text) ) echo '<option value="" '.$selected_default.' >'.$select_default_text.'</option>'; 76 foreach($posts as $p) { //iterate posts 77 $selected = ''; 78 foreach($post_ids as $pid) { //iterate selected posts 79 if($p->ID == $pid && !empty( $post_ids[0] ) ) { 80 $selected = ' selected '; 81 } 82 } 83 echo '<option value="'.$p->ID.'"'.$selected.'>'.$p->post_title.'</option>'; 84 } 85 echo '</select>'; 86 } 87 88 private static function get_all_posts_of_current_post_type() { 89 $post_type = WpobPlugin::get_admin_screen_current_post_type(); 90 $post_types = $post_type; 91 if($post_types == '') $post_types = WpobPlugin::get_all_public_post_types_names(); 92 $pargs = array( 'posts_per_page' => 9999, 'orderby' => 'title', 'order' => 'asc', 'post_type' => $post_types ); 93 94 return get_posts($pargs); 95 } 96 97 private static function is_no_exclude_ids_of_post_type($post_type, $db_ids ) { 98 if( empty( $db_ids[0] ) ) return true; //no exclude ids 99 if( empty( $post_type ) ) return false; //general page - no specific post type 100 $posts = WpobPlugin::get_all_posts_of_current_post_type(); 101 foreach($posts as $p) { //iterate found posts 102 foreach($db_ids as $pid) { //iterate selected posts 103 if($p->ID == $pid ) { 104 return false; 105 } 106 } 107 } 108 return true; 57 109 } 58 110 … … 98 150 $this->page_hook_suffix[] = add_submenu_page( 'options-general.php', 'wpob general settings', 'WP Order By Settings', 'manage_options', 'wpob-settings-wpob_general', array($this,'wpob_draw_general_settings')); 99 151 100 $post_types = $this->get_all_public_post_types_names();152 $post_types = WpobPlugin::get_all_public_post_types_names(); 101 153 // add submenu for all public post types 102 154 foreach ( $post_types as $name ) { … … 108 160 //register all panels 109 161 public function register_wpob_settings() { 110 $post_types = $this->get_all_public_post_types_names();162 $post_types = WpobPlugin::get_all_public_post_types_names(); 111 163 foreach ( $post_types as $name ) { 112 164 $this->register_wpob_settings_for_post_type($name); … … 116 168 public function register_wpob_settings_for_post_type($post_type_name) { 117 169 170 $plural_pname = !empty( $this->current_post_type->labels->name ) ? $this->current_post_type->labels->name : ''; 118 171 register_setting( 'wpob-options-'.$post_type_name, 'wpob-options-'.$post_type_name ); 119 172 add_settings_section('wpob_main_'.$post_type_name, '', array($this,'plugin_section_text'), 'wpob-menu-'.$post_type_name); 120 173 add_settings_field('wpob-fields-'.$post_type_name, __('Choose Order','wp-order-by-plugin'), array($this, 'draw_settings_page'), 'wpob-menu-'.$post_type_name, 'wpob_main_'.$post_type_name, array('post_type' => $post_type_name) ); 174 175 register_setting( 'wpob-options-'.$post_type_name, 'wpob-exclude-posts', array( $this, 'merge_excluded' ) ); 176 add_settings_section('wpob_main_'.$post_type_name, '', array($this,'plugin_section_text'), 'wpob-extra-'.$post_type_name); 177 add_settings_field('wpob-fields-exclude', __('Choose Excluded '.$plural_pname,'wp-order-by-plugin'), array($this, 'draw_settings_page_extra'), 'wpob-extra-'.$post_type_name, 'wpob_main_'.$post_type_name, array('post_type' => $post_type_name) ); 178 } 179 180 public function merge_excluded($exclude) { 181 182 $pt = !empty( $_POST['post_type'] ) ? $_POST['post_type'] : ''; 183 184 $db_exclude = get_option('wpob-exclude-posts'); 185 if( !is_array( $db_exclude ) ) $db_exclude = array(); 186 foreach ( $db_exclude as $key => $val ) { 187 188 $tmp_post = get_post( $val ); 189 $tmp_pt = $tmp_post->post_type; 190 if($tmp_pt == $pt) { 191 unset($db_exclude[$key]); 192 $db_exclude = array_values($db_exclude); 193 } 194 195 } 196 197 if( !empty( $exclude[0] ) ) { 198 $db_exclude = array_unique( array_merge( $exclude, $db_exclude ) ); 199 } 200 201 return $db_exclude; 121 202 } 122 203 123 204 public function plugin_section_text($arg) { 124 } 125 126 //make sure we are on existing post-type 205 206 } 207 208 //make sure we are on existing post-type and set $this->current_post_type with the post type object 127 209 public function checkPost() { 128 210 if ( isset($_GET['page']) && substr($_GET['page'], 0, 14) == 'wpob-settings-' && $_GET['page'] != 'wpob-settings-wpob_general') { … … 137 219 public function update_all_settings() { 138 220 139 $post_types = $this->get_all_public_post_types_names();221 $post_types = WpobPlugin::get_all_public_post_types_names(); 140 222 $updated = 'true'; 141 223 142 224 if(!empty($_POST['wpob-options-']) && $_POST['wpob-options-'] != get_option( 'wpob-options-' )) { 143 225 $is_update_general = update_option( 'wpob-options-', $_POST['wpob-options-'] ); 226 if(!$is_update_general) $updated = 'false'; 227 } 228 $exclude = $_POST["wpob-exclude-posts"]; 229 if(empty($exclude)) $exclude = array(''); 230 if($exclude != get_option( 'wpob-exclude-posts' )) { 231 $is_update_general = update_option( 'wpob-exclude-posts', $exclude ); 144 232 if(!$is_update_general) $updated = 'false'; 145 233 } … … 155 243 } 156 244 157 //call the actual drawing function for general settings panel245 //call the actual drawing function for all settings panel 158 246 public function draw_settings_page($args) { 159 247 160 248 $options = get_option('wpob-options-'.$args['post_type']); 161 249 if($options=='' || !$options) $options = 'datedesc'; … … 163 251 $args['options'] = $options; 164 252 $this->view('form_elements',$args); 253 } 254 255 //call the actual drawing function for all settings panel 256 public function draw_settings_page_extra($args) { 257 $db_exclude = get_option('wpob-exclude-posts'); 258 $plural_pname = !empty( $this->current_post_type->labels->name ) ? $this->current_post_type->labels->name : ''; 259 if( !is_array( $db_exclude ) ) $db_exclude = array(); 260 $args['wpob-exclude-posts'] = $db_exclude; 261 $args['wpob-post-type-label'] = $plural_pname; 262 if( empty( $args['wpob-post-type-label'] ) ) $args['wpob-post-type-label'] = 'ANY'; 263 $this->view('form_extra',$args); 165 264 } 166 265 … … 175 274 176 275 <?php wp_nonce_field('wpob-options-nonce'); ?> 276 177 277 <?php settings_fields( 'wpob-options-'.$this->current_post_type->name ); ?> 178 278 <?php do_settings_sections( 'wpob-menu-'.$this->current_post_type->name ); ?> 279 <?php do_settings_sections( 'wpob-extra-'.$this->current_post_type->name ); ?> 280 179 281 <?php $pt = (!empty($_GET["post_type"])) ? $_GET["post_type"] : 'post'; ?> 180 282 <input type="hidden" name="post_type" value="<?php echo $pt; ?>" /> … … 203 305 <?php wp_nonce_field('wpob-options-nonce'); ?> 204 306 <?php $this->draw_settings_page( array('post_type' => '')); ?> 307 <?php $this->draw_settings_page_extra( array('post_type' => '')); ?> 205 308 <p> 206 309 <input type="submit" value="<?php echo __('Save Changes','wp-order-by-plugin'); ?>" class="button button-primary" /> … … 228 331 // filter the query and return the ordered posts 229 332 function get_ordered_posts( $query ) { 230 333 231 334 if( !is_admin() && ( $query->is_archive || $query->is_category ) ) { 335 336 //exit function if we are in excluded page 337 global $post; 338 $exclude = get_option('wpob-exclude-posts'); 339 if( !empty( $exclude ) && !empty( $post ) ) { 340 foreach($exclude as $pid) { //iterate excluded posts from db record 341 if($post->ID == $pid) { 342 return; 343 } 344 } 345 } 346 232 347 if( !empty($query->query_vars['post_type']) ) { 233 348 $pt = $query->query_vars['post_type']; -
wp-order-by/trunk/css/wpob.css
r1289010 r1314584 20 20 margin-top: 20px!important; 21 21 } 22 .exclude_container { 23 margin-top: 22px; 24 } 25 26 #posts_select_box { 27 height: 203px; 28 padding: 2px 4px; 29 } -
wp-order-by/trunk/readme.txt
r1311195 r1314584 5 5 Requires at least: 4.1 6 6 Tested up to: 4.4 7 Stable tag: 1. 2.57 Stable tag: 1.3 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 14 14 Simple and easy way to order your posts, pages or any other custom post-type in a various options, with the ability to define a different logic for each content type. 15 15 16 The plugin let you order by many options, including: Date ascending or Descending, Last Modified Date, Title Ascending or Descending, Author, Post,Page or post-type Id, Randomly, Number of Comments, Custom Fields and more...17 16 A new menu will appear on the admin side-menu under each content type that is defined on your site (posts, pages etc.) and it will also be added automatically to future custom post types you will add in the future. 18 17 In addition, under the *Settings* menu in WordPress you will find a general settings sub-menu to set global options for the plugin. 19 18 20 **Something is wrong with this plugin on your site? Please create a ticket at WordPress forum and I'll fix it.** 19 **Something is wrong with this plugin on your site? Please create a ticket at WordPress forum, 20 Or email me to [weiluri@gmail.com](mailto:weiluri@gmail.com) and I'll fix it. 21 You are welcome to suggest and request features to be added to the next versions. I'll be glad to hear.** 22 23 **Ordering Options** 24 + Date Descending (WordPress default) 25 + Last Modified Date (Descending) 26 + Title Ascending 27 + Title Descending 28 + Author (Alphabet Ascending order) 29 + Post,Page or post-type Id 30 + Post/Page Parent Id (Descending) 31 + Menu Order (Descending) 32 + Randomly 33 + Number of Comments (Descending, from many to few) 34 + By Custom Field 35 36 **Extra Feature** 37 + Exclude ordering for a specific page/s on your site 38 39 I'll appreciate if you rate me on the plugin page. 40 I'm doing my best to maintain and improve this plugin. if you feel like donate a small amount, of your choice, through the donation link on the plugin page, I will be very glad :) 41 42 Enjoy... 21 43 22 44 == Installation == … … 33 55 = What about support? = 34 56 35 Create a support ticket at WordPress forum and I will take care of any issue.57 You can mail me to [weiluri@gmail.com](mailto:weiluri@gmail.com), or create a support ticket at WordPress forum and I will take care of any issue. 36 58 37 59 == Screenshots == … … 40 62 41 63 == Changelog == 64 65 = 1.3 = 66 - Extra feature added. The option to exclude ordering on specific page/s 42 67 43 68 = 1.2.5 = -
wp-order-by/trunk/views/form_elements.php
r1291134 r1314584 78 78 <p class="warning">Warning: if your custom field contains both numeric and string values this order option may give an unpredictable results </p> 79 79 </div> 80 80 81 </div> -
wp-order-by/trunk/wp-order-by.php
r1311189 r1314584 4 4 * Plugin URI: https://wordpress.org/plugins/wp-order-by/ 5 5 * Description: A wordpress post, post types and pages ordering plugin 6 * Version: 1. 2.56 * Version: 1.3 7 7 * Author: Uri Weil 8 8 * Text Domain: wp-order-by
Note: See TracChangeset
for help on using the changeset viewer.