Пример #1
0
 public function can_output($hook_suffix = '')
 {
     if (WPAlchemy_MetaBox::_is_post() or WPAlchemy_MetaBox::_is_page()) {
         return true;
     }
     return false;
 }
Пример #2
0
 function __construct($arr)
 {
     if (!is_array($arr) and file_exists($arr)) {
         $arr = (include $arr);
     }
     parent::__construct($arr);
     // Modify title in dev mode
     if ($this->is_dev_mode) {
         $this->title = __('[Development Mode] ', 'vp_textdomain') . $this->title;
     }
     if ($this->can_output() and VP_WP_Admin::is_post_or_page()) {
         // make sure metabox template loaded
         if (!is_array($this->template) and file_exists($this->template)) {
             $this->template = (include $this->template);
         }
         add_action('init', array($this, 'register_fields'));
     }
     self::$pool[$this->id] = $this;
 }
Пример #3
0
 /**
  * [taken from WPAlchemy Class by Dimas Begunoff]
  * Used to check for the current post type, works when creating or editing a
  * new post, page or custom post type.
  *
  * @static
  * @return	string [custom_post_type], page or post
  */
 public static function get_current_post_type()
 {
     if (!class_exists('WPAlchemy_MetaBox')) {
         require_once VP_FileSystem::instance()->resolve_path('includes', 'wpalchemy/MetaBox');
     }
     $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL;
     if (isset($uri)) {
         $uri_parts = parse_url($uri);
         $file = basename($uri_parts['path']);
         if ($uri and in_array($file, array('post.php', 'post-new.php'))) {
             $post_id = WPAlchemy_MetaBox::_get_post_id();
             $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : NULL;
             $post_type = $post_id ? get_post_type($post_id) : $post_type;
             if (isset($post_type)) {
                 return $post_type;
             } else {
                 // because of the 'post.php' and 'post-new.php' checks above, we can default to 'post'
                 return 'post';
             }
         }
     }
     return NULL;
 }
Пример #4
0
 /**
  * Cleans an array, removing blank ('') values
  *
  * @static
  * @since	1.0
  * @access	public
  * @param	array the array to clean (passed by reference)
  */
 function clean(&$arr)
 {
     if (is_array($arr)) {
         foreach ($arr as $i => $v) {
             if (is_array($arr[$i])) {
                 WPAlchemy_MetaBox::clean($arr[$i]);
                 if (!count($arr[$i])) {
                     unset($arr[$i]);
                 }
             } else {
                 if ('' == trim($arr[$i]) or is_null($arr[$i])) {
                     unset($arr[$i]);
                 }
             }
         }
         if (!count($arr)) {
             $arr = array();
         } else {
             $keys = array_keys($arr);
             $is_numeric = TRUE;
             foreach ($keys as $key) {
                 if (!is_numeric($key)) {
                     $is_numeric = FALSE;
                     break;
                 }
             }
             if ($is_numeric) {
                 $arr = array_values($arr);
             }
         }
     }
 }
Пример #5
0
 function force_save($post_id)
 {
     /**
      * note: the "save_post" action fires for saving revisions and post/pages,
      * when saving a post this function fires twice, once for a revision save,
      * and again for the post/page save ... the $post_id is different for the
      * revision save, this means that "get_post_meta()" will not work if trying
      * to get values for a revision (as it has no post meta data)
      * see http://alexking.org/blog/2008/09/06/wordpress-26x-duplicate-custom-field-issue
      *
      * why let the code run twice? wordpress does not currently save post meta
      * data per revisions (I think it should, so users can do a complete revert),
      * so in the case that this functionality changes, let it run twice
      */
     $real_post_id = isset($_POST['post_ID']) ? $_POST['post_ID'] : NULL;
     //        // check autosave
     //        if (defined('DOING_AUTOSAVE') AND DOING_AUTOSAVE AND !$this->autosave) return $post_id;
     //
     //        // make sure data came from our meta box, verify nonce
     //        $nonce = isset($_POST[$this->id.'_nonce']) ? $_POST[$this->id.'_nonce'] : NULL ;
     //        if (!wp_verify_nonce($nonce, $this->id)) return $post_id;
     //
     //        // check user permissions
     //        if ($_POST['post_type'] == 'page')
     //        {
     //            if (!current_user_can('edit_page', $post_id)) return $post_id;
     //        }
     //        else
     //        {
     //            if (!current_user_can('edit_post', $post_id)) return $post_id;
     //        }
     // authentication passed, save data
     $new_data = isset($_POST[$this->id]) ? $_POST[$this->id] : NULL;
     WPAlchemy_MetaBox::clean($new_data);
     if (empty($new_data)) {
         $new_data = NULL;
     }
     // filter: save
     if ($this->has_filter('save')) {
         $new_data = $this->apply_filters('save', $new_data, $real_post_id);
         /**
          * halt saving
          * @since 1.3.4
          */
         if (FALSE === $new_data) {
             return $post_id;
         }
         WPAlchemy_MetaBox::clean($new_data);
     }
     // get current fields, use $real_post_id (checked for in both modes)
     $current_fields = get_post_meta($real_post_id, $this->id . '_fields', TRUE);
     if ($this->mode == WPALCHEMY_MODE_EXTRACT) {
         $new_fields = array();
         if (is_array($new_data)) {
             foreach ($new_data as $k => $v) {
                 $field = $this->prefix . $k;
                 array_push($new_fields, $field);
                 $new_value = $new_data[$k];
                 if (is_null($new_value)) {
                     delete_post_meta($post_id, $field);
                 } else {
                     update_post_meta($post_id, $field, $new_value);
                 }
             }
         }
         $diff_fields = array_diff((array) $current_fields, $new_fields);
         if (is_array($diff_fields)) {
             foreach ($diff_fields as $field) {
                 delete_post_meta($post_id, $field);
             }
         }
         delete_post_meta($post_id, $this->id . '_fields');
         if (!empty($new_fields)) {
             add_post_meta($post_id, $this->id . '_fields', $new_fields, TRUE);
         }
         // keep data tidy, delete values if previously using WPALCHEMY_MODE_ARRAY
         delete_post_meta($post_id, $this->id);
     } else {
         if (is_null($new_data)) {
             delete_post_meta($post_id, $this->id);
         } else {
             update_post_meta($post_id, $this->id, $new_data);
         }
         // keep data tidy, delete values if previously using WPALCHEMY_MODE_EXTRACT
         if (is_array($current_fields)) {
             foreach ($current_fields as $field) {
                 delete_post_meta($post_id, $field);
             }
             delete_post_meta($post_id, $this->id . '_fields');
         }
     }
     // action: save
     if ($this->has_action('save')) {
         $this->do_action('save', $new_data, $real_post_id);
     }
     return $post_id;
 }