Example #1
0
 /**
  * Setup arguments.
  *
  * @param  array $args
  */
 protected function setup_args(array $args)
 {
     foreach ($args as $key => $value) {
         if (isset($this->{$key})) {
             $this->{$key} = papi_esc_html($value);
         }
     }
     if (empty($this->id)) {
         $this->id = strtolower(papi_f(papi_underscorify(papify($this->title))));
     }
 }
Example #2
0
 /**
  * Setup arguments.
  *
  * @param  array $args
  */
 private function setup_args(array $args)
 {
     $excluded_keys = ['properties'];
     foreach ($args as $key => $value) {
         if (isset($this->{$key}) && !in_array($key, $excluded_keys)) {
             $this->{$key} = papi_esc_html($value);
         }
     }
     if (empty($this->id)) {
         $this->id = strtolower(papi_f(papi_underscorify(papify($this->title))));
     }
 }
 /**
  * Get meta box id.
  *
  * @param string $slug
  *
  * @return string
  */
 private function get_meta_box_id($slug)
 {
     return papi_f(papi_underscorify(papify($slug)));
 }
 /**
  * Get the html id attribute value.
  *
  * @param  object|string $suffix
  * @param  int $row
  *
  * @return string
  */
 public function html_id($suffix = '', $row = null)
 {
     if (is_array($suffix) || is_object($suffix)) {
         return papi_f($this->html_name($suffix, $row));
     } else {
         $suffix = empty($suffix) || !is_string($suffix) ? '' : '_' . $suffix;
         $suffix = papi_underscorify(papi_slugify($suffix));
     }
     $name = $this->html_name();
     $len = strlen($name);
     if (isset($name[$len - 1]) && $name[$len - 1] === ']') {
         return papi_f(sprintf('%s%s]', substr($name, 0, $len - 1), $suffix));
     }
     return papi_f(sprintf('%s%s', $this->html_name(), $suffix));
 }
Example #5
0
/**
 * Convert array of arrays to array of slugs.
 * The given slug will match a key with the number of properties.
 *
 * @param  array  $value
 * @param  string $slug
 *
 * @return array
 */
function papi_to_property_array_slugs(array $value, $slug)
{
    $results = [];
    $counter = [];
    foreach ($value as $index => $arr) {
        if (!is_array($arr)) {
            continue;
        }
        $counter[] = $arr;
        foreach ($arr as $key => $val) {
            if (!is_string($key) || empty($key)) {
                continue;
            }
            if ($key[0] !== '_') {
                $key = '_' . $key;
            }
            $item_slug = $slug . '_' . $index . $key;
            if (papi_is_property_type_key($item_slug)) {
                $item_slug = papi_f($item_slug);
            }
            $results[$item_slug] = $val;
        }
    }
    $results[$slug] = count($counter);
    return $results;
}
 /**
  * Remove all repeater rows from the database.
  *
  * @param int    $post_id
  * @param string $repeater_slug
  */
 protected function remove_repeater_rows($post_id, $repeater_slug)
 {
     global $wpdb;
     $option_page = $this->is_option_page();
     $repeater_slug = $repeater_slug . '_%';
     if ($option_page) {
         $table = $wpdb->prefix . 'options';
         $sql = "SELECT * FROM {$table} WHERE (`option_name` LIKE %s OR `option_name` LIKE %s AND NOT `option_name` = %s)";
         $query = $wpdb->prepare($sql, $repeater_slug, papi_f($repeater_slug), papi_get_property_type_key_f($repeater_slug));
     } else {
         $table = $wpdb->prefix . 'postmeta';
         $sql = "SELECT * FROM {$table} WHERE `post_id` = %d AND (`meta_key` LIKE %s OR `meta_key` LIKE %s AND NOT `meta_key` = %s)";
         $query = $wpdb->prepare($sql, $post_id, $repeater_slug, papi_f($repeater_slug), papi_get_property_type_key_f($repeater_slug));
     }
     $results = $wpdb->get_results($query);
     foreach ($results as $res) {
         if ($option_page) {
             $key = $res->option_name;
         } else {
             $key = $res->meta_key;
         }
         papi_delete_property_meta_value($post_id, $key);
     }
 }