Advertisement
Guest User

php 7.4 notices

a guest
May 20th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1. <?php
  2. if ( class_exists( 'RWMB_Field' ) ) {
  3.  
  4.   class RWMB_Unit_Field extends RWMB_Checkbox_List_Field {
  5.  
  6.     public function __construct(){
  7.  
  8.       add_action( 'init', array( $this, 'is_edit_page' ), 1 );
  9.  
  10.     }
  11.  
  12.       /**
  13.        * Gets the post status.
  14.       */
  15.       public static function is_edit_page( $new_edit = null ){
  16.         global $pagenow;
  17.  
  18.         if (!is_admin()) return false;
  19.         if ( $pagenow === 'index.php' ) return true; //don't run on dashboard
  20.         if ( $pagenow === 'edit.php' ) return true; //doesn't work
  21.         if ( $pagenow === 'plugins.php' ) return true; //don't run plugin pages
  22.         if ( $pagenow === 'admin.php' ) return true; //don't run on general admin pages
  23.  
  24.  
  25.         if( $new_edit === 'edit' )
  26.           return in_array( $pagenow, array( 'post.php' ) );
  27.         elseif($new_edit === 'new')
  28.           return in_array( $pagenow, array( 'post-new.php' ) );
  29.         else //check for either new or edit
  30.           return in_array( $pagenow, array( 'post.php', 'post-new.php') );
  31.       }
  32.  
  33.     public static function normalize( $field ) {
  34.  
  35.       global $post;
  36.       global $pagenow;
  37.  
  38.       $post_id = false;
  39.  
  40.       if ( $pagenow =='edit.php' ) return;
  41.  
  42.       $post_status = RWMB_Unit_Field::is_edit_page('new');
  43.      
  44.  
  45.       if ( $post_status && !is_null($field) ){
  46.         $field = parent::normalize( $field );
  47.         return $field;
  48.       }
  49.  
  50.       if ('post.php' === $pagenow &&  isset( $_GET['post'] ) ) {
  51.         $post_id = intval( $_GET['post'] );
  52.       } elseif ( isset( $_POST['post_ID'] ) ) {
  53.         $post_id = intval( $_POST['post_ID'] );
  54.       }else{
  55.         return;
  56.       }
  57.  
  58.       $categories = (array) get_the_category($post_id);
  59.  
  60.       if (empty($categories)) return;
  61.  
  62.       foreach ( (array) get_the_category($post->ID) as $cat ) {
  63.  
  64.         if ( empty( $cat->slug ) )
  65.           continue;
  66.  
  67.         $options = array();
  68.  
  69.         foreach ( $categories as $category ) {
  70.           if ( empty($category->slug ) ) {
  71.             continue;
  72.           }
  73.           $term_id = get_queried_object_id();
  74.  
  75.           // get data out of term meta field
  76.           $units = rwmb_meta( 'department_units', array( 'object_type' => 'term' ), $category->term_id, false) ;
  77.  
  78.           if (!empty($units)) {
  79.             foreach($units as $unit) {
  80.               $options[urlencode($unit['name'])] = $category->name . ' - ' . $unit['name'];
  81.             }
  82.           }
  83.         }
  84.  
  85.         $field['options'] = $options;
  86.       }
  87.      
  88.       if (!is_null($field)) {
  89.         $field = parent::normalize( $field );
  90.         return $field;
  91.       }
  92.     }
  93.   }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement