/** * 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)))); } }
/** * 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)))); } }
/** * Setup property options. * * @param mixed $options * * @return mixed */ private function setup_options($options = []) { // When a object is sent in, just return it. if (is_object($options)) { return $options; } // Only arrays can be handled. if (!is_array($options)) { $options = []; } // Merge default options with the given options array. $options = array_merge($this->default_options, $options); $options = (object) $options; // Capabilities should be a array. $options->capabilities = papi_to_array($options->capabilities); // Setup property slug. $options->slug = $this->setup_options_slug($options); // Setup property settings. $options->settings = $this->setup_options_settings($options); // Type should always be lowercase. $options->type = strtolower($options->type); // Escape all options except those that are send it as second argument. return papi_esc_html($options, ['before_html', 'html', 'after_html']); }
/** * Setup meta data. */ protected function setup_meta_data() { foreach ($this->get_meta() as $key => $value) { if (substr($key, 0, 1) === '_') { continue; } $this->{$key} = papi_esc_html($value); } if ($this->sort_order === 1000) { $this->sort_order = papi_filter_settings_sort_order(); } }
/** * Papi escape html. * * @param mixed $obj * @param array $keys * * @return mixed */ function papi_esc_html($obj, $keys = []) { $object = is_object($obj) && get_class($obj) === 'stdClass'; if ($object) { $obj = (array) $obj; } if (is_array($obj)) { foreach ($obj as $key => $value) { if (in_array($key, $keys)) { continue; } if (is_string($key)) { unset($obj[$key]); $key = papi_esc_html($key); } if (is_string($value) || is_object($value) || is_array($obj)) { $obj[$key] = papi_esc_html($value, $keys); } } if ($object) { return (object) $obj; } return $obj; } else { if (is_string($obj)) { return esc_html($obj); } else { return $obj; } } }
/** * Setup page type meta data. */ private function setup_meta_data() { $meta_method = method_exists($this->_class_name, $this->_meta_method) ? $this->_meta_method : $this->_core_meta_method; if (!method_exists($this->_class_name, $meta_method)) { return; } foreach (call_user_func([$this, $meta_method]) as $key => $value) { if (substr($key, 0, 1) === '_') { continue; } $this->{$key} = papi_esc_html($value); } }
/** * Add a new tab. * * @param mixed $file_or_options * @param array $properties * * @return array */ protected function tab($file_or_options = [], $properties = []) { if (!is_string($file_or_options) && !is_array($file_or_options)) { return; } $tab = papi_tab($file_or_options, $properties); // Tabs sometimes will be in $tab->options['options'] when you use a tab template in this method // and using the return value of papi_tab function is used. // // This should be fixed later, not a priority for now since this works. if (is_object($tab) && isset($tab->options) && isset($tab->options['options'])) { $tab = (object) $tab->options; } if (isset($tab->options)) { $tab->options = papi_esc_html($tab->options); } return $tab; }