コード例 #1
0
 /**
  * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
  *
  * @access protected
  * @param int $id The id to retrieve the model object for. If empty we set a default object.
  * @return void
  */
 protected function _set_model_object($id = NULL)
 {
     if (empty($this->_cpt_model_names) || !isset($this->_cpt_routes[$this->_req_action]) || is_object($this->_cpt_model_obj) && $this->_cpt_model_obj->ID() == $id) {
         //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
         return;
     }
     // load CPT object model
     $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
     $this->_cpt_model_obj = !empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
     //d( $this->_cpt_model_obj );
     do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
 }
コード例 #2
0
 /**
  * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL insert/updates
  * @param  int    $post_id ID of post being updated
  * @param  WP_Post $post    Post object from WP
  * @param  bool   $update  Whether this is an update or a new save.
  * @return void
  */
 public function insert_update($post_id, $post, $update)
 {
     //make sure that if this is a revision OR trash action that we don't do any updates!
     if (isset($this->_req_data['action']) && ($this->_req_data['action'] == 'restore' || $this->_req_data['action'] == 'trash')) {
         return;
     }
     $this->_set_model_object($post_id, true);
     //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
     if ($update && (!$this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id)) {
         return;
     }
     //check for autosave and update our req_data property accordingly.
     /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
     			foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
     
     				foreach ( (array) $values as $key => $value ) {
     					$this->_req_data[$key] = $value;
     				}
     			}
     
     		}/**/
     //TODO reactivate after autosave is implemented in 4.2
     //take care of updating any selected page_template IF this cpt supports it.
     if ($this->_supports_page_templates($post->post_type) && !empty($this->_req_data['page_template'])) {
         $post->page_template = $this->_req_data['page_template'];
         $page_templates = wp_get_theme()->get_page_templates($post);
         if ('default' != $this->_req_data['page_template'] && !isset($page_templates[$this->_req_data['page_template']])) {
             EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         } else {
             update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
         }
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     //TODO we'll remove this after reimplementing autosave in 4.2
     $this->_insert_update_cpt_item($post_id, $post);
 }