Plugin Directory

Changeset 1128314


Ignore:
Timestamp:
04/05/2015 07:54:58 PM (11 years ago)
Author:
tryon
Message:

Added a screen option to the my sites page that saves the option data to a user account

Location:
sort-my-sites/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sort-my-sites/trunk/admin/class-sort-my-sites-admin.php

    r1104265 r1128314  
    1313        $this->options = $this->plugin->get_options();
    1414
    15         add_action( 'admin_init', array( $this, 'setup' ) );
     15
     16        add_action( 'wpmu_options', array( $this, 'add_network_options' ) );
     17        add_action( 'update_wpmu_options', array( $this, 'save_network_settings' ) );
     18
     19        add_filter( 'screen_settings', array( $this, 'show_screen_options' ), 10, 2 );
     20        add_filter( 'set-screen-option',  array( $this, 'set_screen_options' ), 11, 3 );
    1621
    1722    }
     
    2530        return self::$instance;
    2631    }
     32   
    2733
     34    function set_screen_options($status, $option, $value) {
     35        if ( 'sort_my_sites_options' == $option ) {
     36            $value = $_POST['sort-my-sites_options'];
     37        }
     38        return $value;
     39    }   
    2840
    29     public function setup(){
     41    function show_screen_options( $status, $args ) {
    3042
    31         add_action( 'wpmu_options', array( $this, 'add_network_options' ) );
    32         add_action( 'update_wpmu_options', array( $this, 'save_network_settings' ) );
     43        $return = $status;
    3344
     45            if ( $args->base == 'my-sites' ) { 
     46
     47                $button = get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false );
     48               
     49                $return .= "
     50                    <fieldset>
     51                        <legend>Sort Options</legend>
     52                        <div class='metabox-prefs'>
     53                            <div><input type='hidden' name='wp_screen_options[option]' value='" .  $this->plugin_slug . "_options' /></div>
     54                            <div><input type='hidden' name='wp_screen_options[value]' value='yes' /></div>
     55                            <div class='custom_fields'>
     56                                <label for='order_by'>Order By:</label>
     57                                <select name='" .  $this->plugin_slug . "_options[order_by]' id='order_by'>";
     58
     59                                    foreach($this->options['order_options'] as $option => $title){                 
     60                                        $return .= "<option value='" . $option ."' ". selected( $this->options['order_by'], $option, false ) ." >". $title ."</option>";
     61                                    }
     62
     63                                $return .="</select>
     64                                <label for='case_sensitive'><input type='checkbox' value='1' name='" .  $this->plugin_slug . "_options[case_sensitive]' id='case_sensitive' ". checked( true, $this->options["case_sensitive" ], false ) ." /> Case Sensitive</label>
     65                                <label for='primary_at_top'><input type='checkbox' value='1' name='" .  $this->plugin_slug . "_options[primary_at_top]' id='primary_at_top' ". checked( true, $this->options["primary_at_top" ], false ) ." /> Keep primary site at the top</label>
     66                            </div>
     67                        </div>
     68                    </fieldset>
     69                    <br class='clear'>
     70                    $button";
     71            }
     72
     73        return $return;
    3474    }
    3575
  • sort-my-sites/trunk/sort-my-sites.php

    r1104265 r1128314  
    66Author: Tryon Eggleston
    77Author URI: https://github.com/tryonegg/
    8 Version: 1.0
     8Version: 1.1
    99Network: true
    1010*/
     
    1515
    1616class sort_my_sites {
    17     const VERSION = 1;
     17    const VERSION = 1.1;
    1818    protected $plugin_slug = 'sort-my-sites';
    1919    protected static $instance = null;
     
    4343    private function __construct() {
    4444
    45         if(is_multisite()){
     45        add_filter( 'get_blogs_of_user', array( $this, 'sort_sites' ) );
    4646
    47             $this->options['case_sensitive'] = get_site_option(  $this->plugin_slug . "_case_sensitive", $this->options['case_sensitive']  );
    48             $this->options['primary_at_top'] = get_site_option(  $this->plugin_slug . "_primary_at_top", $this->options['primary_at_top']  );
    49             $this->options['order_by'] = get_site_option(  $this->plugin_slug . "_order_by", $this->options['order_by']  );
    50 
    51             add_filter( 'get_blogs_of_user', array( $this, 'sort_sites' ) );
    52         }
     47        $this->options['case_sensitive'] = $this->get_option('case_sensitive');
     48        $this->options['primary_at_top'] = $this->get_option('primary_at_top');
     49        $this->options['order_by'] = $this->get_option('order_by');
    5350
    5451    }
     
    6259        return self::$instance;
    6360    }
     61
     62
     63    /**
     64     * Gets the most relevant option setting
     65     * @param string
     66    */
     67    public function get_option( $option ){
     68
     69        $useroptions = get_user_meta( get_current_user_id(), 'sort_my_sites_options', true);
     70
     71        if( $useroptions ){
     72            if( isset( $useroptions[$option] ) ){
     73                return $useroptions[$option];
     74            } else {
     75                return false;
     76            }
     77        } else {
     78            return get_site_option(  $this->plugin_slug . "_" . $option, $this->options[ $option ]  );
     79        }
     80
     81    }
     82
    6483
    6584    /**
     
    115134
    116135}
    117 add_action( 'plugins_loaded', array( 'sort_my_sites', 'get_instance' ) );
    118136
    119 if ( is_admin() && is_multisite() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
     137if( is_multisite() ){
    120138
    121     require_once( plugin_dir_path( __FILE__ ) . 'admin/class-sort-my-sites-admin.php' );
    122     add_action( 'plugins_loaded', array( 'sort_my_sites_admin', 'get_instance' ) );
     139    add_action( 'plugins_loaded', array( 'sort_my_sites', 'get_instance' ) );
     140
     141    if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
     142
     143        require_once( plugin_dir_path( __FILE__ ) . 'admin/class-sort-my-sites-admin.php' );
     144        add_action( 'plugins_loaded', array( 'sort_my_sites_admin', 'get_instance' ) );
     145
     146    }
    123147
    124148}
Note: See TracChangeset for help on using the changeset viewer.