Plugin Directory

Changeset 1314584


Ignore:
Timestamp:
12/22/2015 09:51:52 PM (10 years ago)
Author:
weiluri
Message:

new version 1.2.3 - exclude feature added

Location:
wp-order-by/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • wp-order-by/trunk/admin-options.php

    r1302126 r1314584  
    77        if ( is_admin() ){
    88            load_plugin_textdomain('wp-order-by', false, basename( dirname( __FILE__ ) ) . '/lang' );
    9            
    109            //register and enqueue plugin scripts and styles
    1110            add_action( 'admin_init', array( $this, 'register_plugin_styles' ) );
     
    3635    );
    3736   
    38     private function get_all_public_post_types_names() { 
     37    private static function get_all_public_post_types_names() { 
    3938        $args = array(
    4039           'public'   => true
     
    5554            else echo '<div id="user_message" class="error"><p><strong>'.$this->data["err_message"].'</strong></p></div>';
    5655        }
     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;
    57109    }
    58110   
     
    98150        $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'));
    99151       
    100         $post_types = $this->get_all_public_post_types_names();
     152        $post_types = WpobPlugin::get_all_public_post_types_names();
    101153        // add submenu for all public post types
    102154        foreach ( $post_types as $name ) {
     
    108160    //register all panels
    109161    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();
    111163        foreach ( $post_types as $name ) {
    112164            $this->register_wpob_settings_for_post_type($name);
     
    116168    public function register_wpob_settings_for_post_type($post_type_name) {
    117169
     170        $plural_pname = !empty( $this->current_post_type->labels->name ) ? $this->current_post_type->labels->name : '';
    118171        register_setting( 'wpob-options-'.$post_type_name, 'wpob-options-'.$post_type_name );
    119172        add_settings_section('wpob_main_'.$post_type_name, '', array($this,'plugin_section_text'), 'wpob-menu-'.$post_type_name);       
    120173        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;
    121202    }
    122203   
    123204    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
    127209     public function checkPost() {
    128210        if ( isset($_GET['page']) && substr($_GET['page'], 0, 14) == 'wpob-settings-' &&  $_GET['page'] != 'wpob-settings-wpob_general') {
     
    137219    public function update_all_settings() {
    138220     
    139         $post_types = $this->get_all_public_post_types_names();
     221        $post_types = WpobPlugin::get_all_public_post_types_names();
    140222        $updated = 'true';
    141223       
    142224        if(!empty($_POST['wpob-options-']) && $_POST['wpob-options-'] != get_option( 'wpob-options-' )) {
    143225            $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 );
    144232            if(!$is_update_general) $updated = 'false';
    145233        }
     
    155243    }
    156244   
    157     //call the actual drawing function for general settings panel
     245    //call the actual drawing function for all settings panel
    158246    public function draw_settings_page($args) {
    159       
     247     
    160248        $options = get_option('wpob-options-'.$args['post_type']);
    161249        if($options=='' || !$options) $options = 'datedesc';
     
    163251        $args['options'] = $options;
    164252        $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);
    165264    }
    166265   
     
    175274           
    176275                <?php wp_nonce_field('wpob-options-nonce'); ?>
     276               
    177277                <?php settings_fields( 'wpob-options-'.$this->current_post_type->name ); ?>
    178278                <?php do_settings_sections( 'wpob-menu-'.$this->current_post_type->name ); ?>
     279                <?php do_settings_sections( 'wpob-extra-'.$this->current_post_type->name ); ?>
     280               
    179281                <?php $pt = (!empty($_GET["post_type"])) ? $_GET["post_type"] : 'post'; ?>
    180282                <input type="hidden" name="post_type" value="<?php echo $pt; ?>" />
     
    203305                <?php wp_nonce_field('wpob-options-nonce'); ?>
    204306                <?php $this->draw_settings_page( array('post_type' => '')); ?>
     307                <?php $this->draw_settings_page_extra( array('post_type' => '')); ?>
    205308                <p>
    206309                    <input type="submit" value="<?php echo __('Save Changes','wp-order-by-plugin'); ?>" class="button button-primary" />
     
    228331// filter the query and return the ordered posts
    229332function get_ordered_posts( $query ) {
    230 
     333               
    231334    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
    232347        if( !empty($query->query_vars['post_type']) ) {
    233348            $pt = $query->query_vars['post_type'];
  • wp-order-by/trunk/css/wpob.css

    r1289010 r1314584  
    2020        margin-top: 20px!important;
    2121}
     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  
    55Requires at least: 4.1
    66Tested up to: 4.4
    7 Stable tag: 1.2.5
     7Stable tag: 1.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1414Simple 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.
    1515
    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...
    1716A 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.
    1817In addition, under the *Settings* menu in WordPress you will find a general settings sub-menu to set global options for the plugin.
    1918
    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,
     20Or email me to [weiluri@gmail.com](mailto:weiluri@gmail.com) and I'll fix it.
     21You 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
     39I'll appreciate if you rate me on the plugin page.
     40I'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
     42Enjoy...
    2143
    2244== Installation ==
     
    3355= What about support? =
    3456
    35 Create a support ticket at WordPress forum and I will take care of any issue.
     57You 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.
    3658
    3759== Screenshots ==
     
    4062
    4163== Changelog ==
     64
     65= 1.3 =
     66- Extra feature added. The option to exclude ordering on specific page/s
    4267
    4368= 1.2.5 =
  • wp-order-by/trunk/views/form_elements.php

    r1291134 r1314584  
    7878        <p class="warning">Warning: if your custom field contains both numeric and string values this order option may give an unpredictable results </p>
    7979    </div>
     80   
    8081</div>
  • wp-order-by/trunk/wp-order-by.php

    r1311189 r1314584  
    44 * Plugin URI: https://wordpress.org/plugins/wp-order-by/
    55 * Description: A wordpress post, post types and pages ordering plugin
    6  * Version: 1.2.5
     6 * Version: 1.3
    77 * Author: Uri Weil
    88 * Text Domain: wp-order-by
Note: See TracChangeset for help on using the changeset viewer.