/** * Add help tabs. */ public function add_help_tabs() { $help = $this->help(); $screen = get_current_screen(); // No screen available. if ($screen instanceof WP_Screen === false) { return; } // Clean up all existing tabs. if (!$this->show_help_tabs || !empty($help)) { $screen->remove_help_tabs(); } // No new help tabs available. if (empty($help)) { return; } // Add help sidebar content. By default it will be disabled // since `help_sidebar` method returns false. $help_sidebar = $this->help_sidebar(); $help_sidebar = papi_maybe_get_callable_value($help_sidebar); $screen->set_help_sidebar(wpautop($help_sidebar)); foreach ($help as $key => $value) { $args = ['id' => papi_html_name($key), 'title' => $key]; if (is_callable($value)) { $args['callback'] = function () use($value) { return wpautop($value()); }; } else { $args['content'] = wpautop($value); } $screen->add_help_tab($args); } }
/** * Get Papi cache key. * * @param string $key * @param mixed $suffix * * @return string */ function papi_cache_key($key, $suffix) { if (!is_string($key)) { return ''; } $key = papify($key); $suffix = papi_convert_to_string($suffix); $suffix = papi_html_name($suffix); $suffix = papi_remove_papi($suffix); return sprintf('%s_%s', $key, $suffix); }
/** * Get Papi cache key. * * @param string $key * @param mixed $suffix * @param string $type * * @return string */ function papi_cache_key($key, $suffix, $type = 'post') { if (!is_string($key)) { return ''; } $type = empty($type) ? 'post' : $type; $type = $type === 'page' ? 'post' : $type; $key = unpapify($key); $key = papify($type . '_' . $key); $suffix = papi_convert_to_string($suffix); $suffix = papi_html_name($suffix); $suffix = unpapify($suffix); return sprintf('%s_%s', $key, $suffix); }
/** * Setup tabs. * * @param array $tabs * * @return array */ function papi_tabs_setup(array $tabs) { $_tabs = []; foreach ($tabs as $tab) { if ($tab instanceof Papi_Core_Tab === false) { continue; } if (papi_current_user_is_allowed($tab->capabilities)) { $_tabs[] = $tab; } } $tabs = papi_sort_order($_tabs); // Generate unique names for all tabs. $len = count($tabs); for ($i = 0; $i < $len; $i++) { $tabs[$i]->id = papi_html_name($tabs[$i]->title) . '_' . $i; } return $tabs; }
/** * Setup tabs. * * @param array $tabs * * @return array */ function papi_setup_tabs(array $tabs) { $_tabs = []; foreach ($tabs as $tab) { $tab = (object) $tab; if (!isset($tab->options)) { continue; } $tab->options = papi_get_tab_options($tab->options); if (papi_current_user_is_allowed($tab->options->capabilities)) { $_tabs[] = $tab; } } $tabs = papi_sort_order($_tabs); // Generate unique names for all tabs. $len = count($tabs); for ($i = 0; $i < $len; $i++) { $tabs[$i]->options->_name = papi_html_name($tabs[$i]->options->title) . '_' . $i; } return $tabs; }
/** * Setup options slug. * * @param stdClass $options * * @return string */ private function setup_options_slug($options) { $slug = $options->slug; // When `slug` is false or not required a unique slug should be generated. if ($slug === false || empty($slug) && $this->slug_required === false) { return '_' . papi_html_name(md5(uniqid(rand(), true))); } // If `slug` is empty, check if `title` is not empty // and generate a slug from the `title` or if empty // use the `type`. if (empty($slug)) { if (empty($options->title)) { $slug = papi_slugify($options->type); } else { $slug = papi_slugify($options->title); } } // Create a html friendly name from the `slug`. return papi_html_name($slug); }
/** * Setup options slug. * * @param stdClass $options * * @return string */ private function setup_options_slug($options) { $slug = $options->slug; if (empty($slug)) { if (empty($options->title)) { $slug = papi_slugify($options->type); } else { $slug = papi_slugify($options->title); } } return $slug === 'papi_' ? '' : papi_html_name($slug); }