Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.99 KB | None | 0 0
  1. <?php
  2. // this document displays and manages the administrative options for the CustomPostOrder plugin.
  3.  
  4. global $userdata;
  5. get_currentuserinfo();
  6.  
  7.  
  8. if ( !current_user_can ( "edit_pages" ) ) die ( __( 'Sorry You can\'t see this' ) ); // only admins can edit this page
  9.  
  10. $CustomPostOrder_Options = array(
  11.     'page_id'   => '',
  12. );
  13.  
  14. /**
  15.  * Returns an array of plugin settings.
  16.  */
  17. function CustomPostOrder_settings() {
  18.     $settings_arr = array(
  19.         'orderElement' => 'post_date',
  20.         'orderby' => 'meta_value meta_value_num',
  21.         'orderType'    => 'DESC',
  22.         'applyTo'      => 'all',
  23.        
  24.         'applyArray'   => ''
  25.     );
  26.     return $settings_arr;
  27. }
  28.  
  29. /**
  30.  * Initializes settings and adds options to database if options are not set.
  31.  * Updates database options if any post variables were submitted.
  32.  * Returns the current CustomPostOrder options from the database.
  33.  */
  34. function CustomPostOrder_updateOptions(){
  35.     $settings      = CustomPostOrder_settings();
  36.     $settings_keys = array_keys ( $settings );
  37.     if ( !get_option ( 'CustomPostOrder-settings' ) ) {
  38.         //add the settings to options
  39.         add_option ('CustomPostOrder-settings', $settings );
  40.     }
  41.     else
  42.         $settings = get_option ( 'CustomPostOrder-settings' );
  43.      
  44.     $input = $settings;
  45.    
  46.    
  47.     if ( $_POST['orderElement'] || $_POST['orderType'] || $_POST['applyTo'] || $_POST['orderby'] || $_POST['applyArray']) {
  48.             check_admin_referer('custom_post_order'); # check for the header we don't go any further if this is not satisfied
  49.             $input['orderby']      = $_post['orderby'];
  50.             $input['orderElement'] = $_POST['orderElement'];
  51.             $input['orderType']    = $_POST['orderType'];
  52.             $input['applyTo']      = $_POST['applyTo'];
  53.             $input['applyArray']   = $_POST['applyArray'];
  54.             update_option ( 'CustomPostOrder-settings', $input );
  55.         }
  56.     return $input;
  57. }
  58.  
  59. /**
  60.  * Displays the Custom Post Order plugin options
  61.  */
  62.  
  63. function CustomPostOrder_Form_init()
  64. {
  65.     global $wpdb, $user_ID, $blog_id;
  66.  
  67.     $option = CustomPostOrder_updateOptions();
  68.     /*
  69.      * If the options already exist in the database then use them,
  70.      * else initialize the database by storing the defaults.
  71.      */
  72.     ?>
  73.    
  74.     <div class="wrap">
  75.     <?php
  76.     if( $_POST ) /* let the user know the options have been updated */
  77.     { ?>
  78.         <div id="message" class="updated fade"><p>Custom Post Order Options Updated</p></div>
  79.     <?php
  80.     }
  81.     // display the options in a form
  82.     ?>
  83.    
  84.     <h2><?php _e("Custom Post Order Options"); ?></h2>
  85.  
  86.     Please select the desired sorting type to be used, when displaying a series of posts:
  87.     <form action="" method="post">
  88.     <?php if ( function_exists('wp_nonce_field') )
  89.                 wp_nonce_field('custom_post_order'); #check the header
  90.     ?>
  91.     <table class="form-table">
  92.                 <tr>
  93.                     <th scope="row">Order By</th>
  94.                     <td>
  95.                         <fieldset><legend class="hidden">Order By</legend>
  96.                         <label><input type="radio" name="orderElement" value="post_date"
  97.     <?php
  98.         if ( $option['orderElement'] == "post_date" ) {
  99.             echo 'checked="checked"';
  100.         }
  101.     ?>  /> Post Date</label> <br />
  102.    
  103.                      <label><input type="radio" name="orderElement" value="post_title"
  104.     <?php
  105.         if ( $option['orderElement'] == "post_title" ) {
  106.             echo 'checked="checked"';
  107.         }
  108.     ?>  /> Post Title</label> <br />
  109.    
  110.                     <label><input type="radio" name="orderElement" value="post_author"
  111.     <?php
  112.         if ( $option['orderElement'] == "post_author" ) {
  113.             echo 'checked="checked"';
  114.         }
  115.     ?>  /> Post Author</label> <br />
  116.                      <label><input type="radio" name="orderElement" value="post_modified"
  117.     <?php
  118.         if ( $option['orderElement'] == "post_modified" ) {
  119.             echo 'checked="checked"';
  120.         }
  121.     ?>  /> Last modified</label> <br />
  122.                     <label><input type="radio" name="orderElement" value="post_name"
  123.     <?php
  124.         if ( $option['orderElement'] == "post_name" ) {
  125.             echo 'checked="checked"';
  126.         }
  127.     ?>  /> Post Name (the post slug)</label> <br />
  128.                         </fieldset>
  129.                     </td>
  130.                 </tr>
  131.    
  132.    
  133.                 <tr>
  134.                     <th scope="row">Order Direction</th>
  135.                     <td>
  136.                         <fieldset><legend class="hidden">Order Direction</legend>
  137.                         <label><input type="radio" name="orderType" value="DESC"
  138.     <?php
  139.         if ( $option['orderType'] == "DESC" ) {
  140.             echo 'checked="checked"';
  141.         }
  142.     ?>  /> Descending ( 4, 3, 2, 1 )</label> <br />
  143.                         <label><input type="radio" name="orderType" value="ASC"
  144.     <?php
  145.         if ( $option['orderType'] == "ASC" ) {
  146.             echo 'checked="checked"';
  147.         }
  148.     ?>  /> Ascending ( 1, 2, 3, 4 )</label> <br />
  149.                         </fieldset>
  150.                     </td>
  151.                 </tr>
  152.  
  153.                
  154.                 <tr>
  155.                     <th scope="row">Apply To</th>
  156.                     <td>
  157.                         <fieldset><legend class="hidden">Apply To</legend>
  158.                         <label><input type="radio" name="applyTo" value="all" onclick="jQuery('#select_categories').hide();"
  159.         <?php
  160.             if ( $option['applyTo'] == 'all' ) {
  161.                 echo 'checked="checked"';
  162.             }
  163.         ?>  /> Apply to all categories </label> <br />
  164.                         <label><input type="radio" name="applyTo" value="selected" onclick="jQuery('#select_categories').show();"
  165.         <?php
  166.             if ( $option['applyTo'] == 'selected' ) {
  167.                 echo 'checked="checked"';
  168.             }
  169.         ?>  /> Apply to selected categories </label>
  170.         <br />
  171.  
  172.                          </fieldset>
  173.                     </td>
  174.                 </tr>
  175.                
  176.                
  177.                     <tr id="select_categories" <?php if( $option['applyTo'] == 'all') {?> style="display:none;" <?php } ?> >
  178.                     <th scope="row" >Selected Categories</th>
  179.                     <td>
  180.                         <fieldset><legend class="hidden">Selected Categories</legend>
  181.                        
  182.             <?php
  183.            
  184.             $cats = get_categories();
  185.      
  186.             foreach ( $cats as $cat ) : ?>
  187.                         <label><input type="checkbox" name="applyArray[]" value="<?php echo $cat->term_id; ?>" <?php if(is_array($option['applyArray']) && in_array($cat->term_id, $option['applyArray'])) echo ' checked="checked"'; ?> >
  188.                 <?php echo $cat->name; ?></label><br />
  189.             <?php endforeach; ?>
  190.  
  191.                          </fieldset>
  192.                     </td>
  193.                 </tr>
  194.  
  195.   </table>
  196.    
  197.     <input type="submit" target=_self class="button" value="Save Options" name="CustomPostOrderOptionButton"/>
  198.     </form>
  199.     </div>
  200.     <?php
  201. }
  202.  
  203. // let's show the form since we are already here
  204. CustomPostOrder_Form_init();
  205.  
  206. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement