/**
  * Save options with a post id of zero.
  */
 public function save_options()
 {
     if (!papi_is_method('post') || !papi_is_option_page()) {
         return;
     }
     // Check if our nonce is vailed.
     if (!wp_verify_nonce(papi_get_sanitized_post('papi_meta_nonce'), 'papi_save_data')) {
         return;
     }
     // Get properties data.
     $data = $this->get_post_data();
     // Prepare properties data.
     $data = $this->prepare_properties_data($data, 0);
     foreach ($data as $key => $value) {
         papi_update_property_meta_value(['post_id' => 0, 'slug' => $key, 'type' => Papi_Option_Page::TYPE, 'value' => $value]);
     }
 }
 /**
  * Save properties with a post id of zero.
  */
 public function save_properties()
 {
     if ($_SERVER['REQUEST_METHOD'] !== 'POST' || papi_get_meta_type() !== 'option') {
         return;
     }
     // Check if our nonce is vailed.
     if (!wp_verify_nonce(papi_get_sanitized_post('papi_meta_nonce'), 'papi_save_data')) {
         return;
     }
     // Get properties data.
     $data = $this->get_post_data();
     // Prepare properties data.
     $data = $this->prepare_properties_data($data, 0);
     foreach ($data as $key => $value) {
         papi_update_property_meta_value(['id' => 0, 'slug' => $key, 'type' => 'option', 'value' => $value]);
     }
     /**
      * Fire `save_properties` action when all is done.
      *
      * @param int    $id
      * @param string $meta_type
      */
     do_action('papi/save_properties', 0, 'option');
 }
예제 #3
0
파일: page.php 프로젝트: ekandreas/papi
/**
 * Update field with new value. The old value will be deleted.
 *
 * @param  int    $post_id
 * @param  string $slug
 * @param  mixed  $value
 * @param  string $type
 *
 * @return bool
 */
function papi_update_field($post_id = null, $slug = null, $value = null, $type = 'page')
{
    if (!is_numeric($post_id) && is_string($post_id)) {
        $value = $slug;
        $slug = $post_id;
        $post_id = null;
    }
    if (!is_string($slug) || empty($slug)) {
        return false;
    }
    if (papi_is_empty($value)) {
        return papi_delete_field($post_id, $slug, $type);
    }
    $post_id = papi_get_post_id($post_id);
    if ($post_id === 0 && $type === Papi_Post_Page::TYPE) {
        return false;
    }
    $page = papi_get_page($post_id, $type);
    if (is_null($page)) {
        return false;
    }
    $property = $page->get_property($slug);
    if (!papi_is_property($property)) {
        return false;
    }
    papi_delete_field($post_id, $slug, $type);
    $value = $property->update_value($value, $slug, $post_id);
    $value = papi_filter_update_value($property->get_option('type'), $value, $slug, $post_id);
    return papi_update_property_meta_value(['type' => $type, 'post_id' => $post_id, 'slug' => $slug, 'value' => $value]);
}
 /**
  * Save properties.
  *
  * @param int $post_id
  */
 public function save_properties($post_id)
 {
     // Pre save page template, page type and some others dynamic values.
     $this->pre_save($post_id);
     // Get properties data.
     $data = $this->get_post_data();
     // Prepare properties data.
     $data = $this->prepare_properties_data($data, $post_id);
     // Overwrite post data if any.
     $this->overwrite_post_data($post_id);
     // Save all properties value
     foreach ($data as $key => $value) {
         papi_update_property_meta_value(['post_id' => $post_id, 'slug' => $key, 'type' => Papi_Post_Page::TYPE, 'value' => $value]);
     }
 }
예제 #5
0
 /**
  * Import data to Papi.
  *
  * @param  mixed $options
  * @param  array $fields
  *
  * @return bool
  */
 public function import($options, array $fields = [])
 {
     $options = $this->get_import_options($options);
     $meta_id = empty($options['meta_id']) ? $options['post_id'] : $options['meta_id'];
     $meta_type = $options['meta_type'];
     $entry_type = $options['page_type'];
     if (isset($options['update_arrays'])) {
         $this->driver->set_options(['update_array' => $options['update_arrays']]);
     }
     if (empty($meta_id) || empty($fields)) {
         return false;
     }
     if (empty($entry_type)) {
         $entry_type = papi_get_entry_type_by_meta_id($meta_id, $meta_type);
     }
     if (is_string($entry_type)) {
         $entry_type = papi_get_entry_type_by_id($entry_type);
     }
     if ($entry_type instanceof Papi_Entry_Type === false) {
         return false;
     }
     update_metadata($meta_type, $meta_id, papi_get_page_type_key(), $entry_type->get_id());
     $result = true;
     foreach ($fields as $slug => $value) {
         if (!is_string($slug) || papi_is_empty($value)) {
             continue;
         }
         $property = $entry_type->get_property($slug);
         if (!papi_is_property($property)) {
             $result = false;
             continue;
         }
         $value = $this->fire_filter(['filter' => 'driver:value', 'type' => 'before', 'value' => [$value, $slug]]);
         $value = $this->get_value(['post_id' => $meta_id, 'property' => $property, 'slug' => $slug, 'value' => $value]);
         $value = $this->fire_filter(['filter' => 'driver:value', 'type' => 'after', 'value' => [$value, $slug]]);
         $out = papi_update_property_meta_value(['id' => $meta_id, 'slug' => $slug, 'type' => $meta_type, 'value' => $value]);
         $result = $out ? $result : $out;
     }
     return $result;
 }
 /**
  * Save properties.
  *
  * @param int $id
  */
 public function save_properties($id)
 {
     // Pre save page template, page type and some others dynamic values.
     $this->pre_save($id);
     // Get properties data.
     $data = $this->get_post_data();
     // Prepare properties data.
     $data = $this->prepare_properties_data($data, $id);
     // Get meta type.
     $meta_type = $this->get_meta_type();
     // Overwrite post data if any.
     if ($meta_type === 'post') {
         $this->overwrite_post_data($id);
     }
     // Save all properties value
     foreach ($data as $key => $value) {
         papi_update_property_meta_value(['id' => $id, 'slug' => $key, 'type' => $this->get_meta_type(), 'value' => $value]);
     }
     /**
      * Fire `save_properties` action when all is done.
      *
      * @param int    $id
      * @param string $meta_type
      */
     do_action('papi/save_properties', $id, $meta_type);
 }
예제 #7
0
파일: page.php 프로젝트: nlemoine/papi
/**
 * Update field with new value. The old value will be deleted.
 *
 * @param  int    $id
 * @param  string $slug
 * @param  mixed  $value
 * @param  string $type
 *
 * @return bool
 */
function papi_update_field($id = null, $slug = null, $value = null, $type = 'post')
{
    if (!is_numeric($id) && is_string($id)) {
        $type = empty($value) ? $value : $type;
        $value = $slug;
        $slug = $id;
        $id = null;
    }
    if (!is_string($slug) || empty($slug)) {
        return false;
    }
    if (papi_is_empty($value)) {
        return papi_delete_field($id, $slug, $type);
    }
    $id = papi_get_meta_id($type, $id);
    $store = papi_get_meta_store($id, $type);
    if (is_null($store)) {
        return false;
    }
    $property = $store->get_property($slug);
    if (!papi_is_property($property)) {
        return false;
    }
    papi_delete_field($id, $slug, $type);
    $value = $property->update_value($value, $slug, $id);
    $value = papi_filter_update_value($property->get_option('type'), $value, $slug, $id, $type);
    return papi_update_property_meta_value(['type' => $type, 'id' => $id, 'slug' => $slug, 'value' => $value]);
}