function render() { $updated = isset($_GET['incsub_event_settings_saved']) && $_GET['incsub_event_settings_saved'] == 1; if (!class_exists('WpmuDev_HelpTooltips')) { require_once eab_plugin_dir() . 'lib/class_wd_help_tooltips.php'; } $tips = new WpmuDev_HelpTooltips(); $tips->set_icon_url(eab_plugin_url() . 'img/information.png'); if (!(defined('EAB_PREVENT_SETTINGS_SECTIONS') && EAB_PREVENT_SETTINGS_SECTIONS)) { $tabbable = 'tabbable'; } else { $tabbable = false; } $hide = !empty($tabbable) ? 'hide' : ''; $archive_tpl = file_exists(get_stylesheet_directory() . '/archive-incsub_event.php') ? get_stylesheet_directory() . '/archive-incsub_event.php' : get_template_directory() . '/archive-incsub_event.php'; $archive_tpl_present = apply_filters('eab-settings-appearance-archive_template_copied', file_exists($archive_tpl)); $single_tpl = file_exists(get_stylesheet_directory() . '/single-incsub_event.php') ? get_stylesheet_directory() . '/single-incsub_event.php' : get_template_directory() . '/single-incsub_event.php'; $single_tpl_present = apply_filters('eab-settings-appearance-single_template_copied', file_exists($single_tpl)); $theme_tpls_present = apply_filters('eab-settings-appearance-templates_copied', $archive_tpl_present && $single_tpl_present); $raw_tpl_sets = glob(EAB_PLUGIN_DIR . 'default-templates/*'); $templates = array(); foreach ($raw_tpl_sets as $item) { if (!is_dir($item)) { continue; } $key = basename($item); $label = ucwords(preg_replace('/[^a-z0-9]+/i', ' ', $key)); $templates[$key] = sprintf(__("Plugin: %s", eab_domain()), $label); } foreach (get_page_templates() as $name => $tpl) { $templates[$tpl] = sprintf(__("Theme: %s", eab_domain()), $name); } include_once 'views/settings-menu.php'; }
/** * Gets templates supported by specific group. * * @param type $group_id * @return type */ function wpcf_admin_get_templates_by_group($group_id) { /** * sanitized $group_id */ $group_id = intval($group_id); if (empty($group_id)) { return array(); } $data = get_post_meta($group_id, '_wp_types_group_templates', true); if ($data == 'all') { return array(); } $data = explode(',', trim($data, ',')); $templates = get_page_templates(); $templates[] = 'default'; $templates_views = get_posts('post_type=view-template&numberposts=-1&status=publish'); foreach ($templates_views as $template_view) { $templates[] = $template_view->ID; } $result = array(); if (!empty($data)) { foreach ($templates as $template) { if (in_array($template, $data)) { $result[] = $template; } } } return $result; }
function body() { global $post; if (0 != count(get_page_templates())) { //$template = !empty($post->page_template) ? $post->page_template : false; $template = get_post_meta($post->ID, '_wp_page_template', true); $template = '' == trim($template) ? false : $template; ?> <p><strong><?php _e('Template', 'rhc'); ?> </strong></p> <label class="screen-reader-text" for="page_template"><?php _e('Page Template', 'rhc'); ?> </label><select name="_wp_page_template" id="_wp_page_template"> <option value='default'><?php _e('Default Template', 'rhc'); ?> </option> <?php page_template_dropdown($template); ?> </select> <?php } }
public function get_visibility_value() { $return = (object) ["templates" => get_page_templates()]; if (isset($_REQUEST["layout_id"]) && ctype_xdigit($_REQUEST["layout_id"]) && isset($_REQUEST["id"]) && is_numeric($_REQUEST["id"])) { $field_id = $_REQUEST["layout_id"]; $post_id = $_REQUEST["id"]; } else { wp_send_json_success($return); } $post = get_post($post_id); $post_obj = unserialize($post->post_content); $found = false; foreach ($post_obj["layouts"] as $obj) { if ($obj["key"] == $field_id) { $found = true; break; } } if (!$found) { wp_send_json_success($return); } if (is_array($obj) && isset($obj["visibility"])) { if (!empty($obj["visibility"])) { $return->visibility = explode(",", $obj["visibility"]); wp_send_json_success($return); } else { wp_send_json_success($return); } } else { wp_send_json_success($return); } }
function get_page_templates() { $templates = get_page_templates(); ksort($templates); $page_templates = array(); if (is_array($templates)) { foreach ($templates as $template) { $template_data = implode('', file(TEMPLATEPATH . "/" . $template)); preg_match('|emplate Name:(.*)$|mi', $template_data, $name); // Using emplate instead of Template intentionally preg_match('|Description:(.*)$|mi', $template_data, $description); preg_match('|Exclude:(.*)$|mi', $template_data, $exclude); $name = $name[1]; $description = $description[1]; $exclude = trim($exclude[1]); if (!empty($name)) { if (!empty($exclude)) { continue; } $page_templates[trim($name)] = basename($template); } } } return $page_templates; }
function fti_page_templates_summary() { echo '<h1>' . _x('Page Template Usage', 'Admin Menu Name', 'pagetemplateusageinfo') . '</h1>'; // Get the List of Templates from the theme $templates = get_page_templates(); // Get the list of templates references in the database $templateUse = fti_page_templates_get_templateUsage(); // Sort array by key ksort($templates); // Print theme count info echo sprintf('<p>' . _x('There are <strong>%d</strong> templates included in the <strong>%s</strong> theme.', 'Template Statistics', 'pagetemplateusageinfo') . '</p>', count($templates), wp_get_theme()); echo '<table id="fti_page_templates_templateList"><thead><tr><th>' . _x('Tempalte Name', 'Table Column Heading', 'pagetemplateusageinfo') . '</th><th>' . _x('Tempalte Filename', 'Table Column Heading', 'pagetemplateusageinfo') . '</th><th>' . _x('# of Pages Using Template', 'Table Column Heading', 'pagetemplateusageinfo') . '</th></tr></thead><tbody>'; // Start with Default Template echo '<tr>'; echo sprintf('<td>%s</td><td>%s</td><td><a href="edit.php?post_type=page&page=fti_page_templates&template=%s">%d</a></td>', 'page.php', 'default', 'page.php', $templateUse['default']->pages_using); echo '</tr>'; // Loop through the themes foreach ($templates as $template_name => $template_filename) { echo '<tr>'; echo sprintf('<td>%s</td><td>%s</td><td><a href="edit.php?post_type=page&page=fti_page_templates&template=%s">%d</a></td>', $template_name, $template_filename, $template_filename, $templateUse[$template_filename]->pages_using); echo '</tr>'; } echo '</tbody></table>'; // Sort the Table by Page Usage echo '<script>jQuery(document).ready(function() { jQuery("#fti_page_templates_templateList").tablesorter({sortList: [[2,0]]}) })</script>'; }
public function addMetaBox() { $templates = get_page_templates(); $template = get_page_template_slug(); if ($this->pageTemplate == 'any' || $templates[$this->pageTemplate] == $template) { add_meta_box($this->id, $this->title, [$this->metaTemplate, 'getHtml'], $this->type, $this->context, $this->priority); } }
/** * Get page templates * @param array $args * @return array */ protected function _get_content($args = array()) { $templates = array_flip(get_page_templates()); if (isset($args['include'])) { $templates = array_intersect_key($templates, array_flip($args['include'])); } return $templates; }
function tf_get_templates() { $tmp = get_page_templates(); $templates = array('none' => __('Select template', 'tfuse')); foreach ($tmp as $key => $val) { $templates[$val] = $key; } return $templates; }
/** * Add custom body class when it's a page type. * * @param string $classes * * @return string */ public function admin_body_class($classes) { if (!in_array($this->post_type, papi_get_post_types())) { return $classes; } if (count(get_page_templates())) { $classes .= 'papi-hide-cpt'; } return $classes; }
/** * @ticket 10959 * @ticket 11216 */ function test_page_templates() { $theme = get_theme('Page Template Theme'); $this->assertFalse(empty($theme)); switch_theme($theme['Template'], $theme['Stylesheet']); $templates = get_page_templates(); $this->assertEquals(3, count($templates)); $this->assertEquals("template-top-level.php", $templates['Top Level']); $this->assertEquals("subdir/template-sub-dir.php", $templates['Sub Dir']); $this->assertEquals("template-header.php", $templates['This Template Header Is On One Line']); }
public static function getPageTemplateNames() { $templates = get_page_templates(); $templates_names = array(); foreach ($templates as $key => $value) { if ($value !== 'landing.php') { $templates_names[$key] = $key; } } return $templates_names; }
/** * Get page templates * * @since 1.0 * @param array $args * @return array */ protected function _get_content($args = array()) { $templates = array_flip(get_page_templates()); if (isset($args['include'])) { $templates = array_intersect_key($templates, array_flip($args['include'])); } if (isset($args["search"]) && $args["search"]) { $this->search_string = $args["search"]; $templates = array_filter($templates, array($this, "_filter_search")); } return $templates; }
public static function admin() { parent::admin(); $tpl = get_page_templates(); if (count($tpl) > 0) { $list = array(); foreach ($tpl as $tplname => $tplfile) { $list[basename($tplfile)] = $tplname; } self::mkGUI(self::$type, self::$option[self::$name], self::$question, self::$info, self::$except, $list); } }
/** * Template areas meta box * @return void */ public function metaBoxTemplateAreas() { global $wp_registered_sidebars; global $modularityOptions; usort($wp_registered_sidebars, function ($a, $b) { return $a['name'] > $b['name']; }); $coreTemplates = \Modularity\Helper\Wp::getCoreTemplates(); $coreTemplates = apply_filters('Modularity/CoreTemplatesInTheme', $coreTemplates); $customTemplates = get_page_templates(); $templates = array_merge($coreTemplates, $customTemplates); include MODULARITY_TEMPLATE_PATH . 'options/partials/modularity-template-areas.php'; }
/** * Inspired from \wp-admin\includes\theme.php::page_template_drowpdown() : * Changes $templates to static because when the function is called for each displayed pages, * it leads to very bad perfomances... */ function cached_page_template_drowpdown($default) { static $templates = array(); $display_template = __('Default Template', ApmConfig::i18n_domain); if (empty($templates)) { $templates = get_page_templates(); } ksort($templates); foreach (array_keys($templates) as $template) { if ($default == $templates[$template]) { $display_template = $template; } } echo $display_template; }
/** * [createPageTemplate description] * @return [type] [description] */ public static function createPageTemplate() { /* Injeta um item no cache de templates para garantir que o dropdown seja * mostrado. Ainda é necessário o javascript porque podemos apenas * sobreescrever as opções, não adicionar. */ if (!count(get_page_templates())) { $cacheKey = 'page_templates-' . md5(get_theme_root() . '/' . get_stylesheet()); wp_cache_set($cacheKey, array('mobilize_force_dropdown' => 'mobilize_force_dropdown'), 'themes', 1800); } wp_enqueue_script('mobilize-edit', plugins_url('/mobilize/assets/js/edit.js', INC_MOBILIZE)); $slug = get_post_meta(get_the_ID(), '_mobilize_template', true); wp_localize_script('mobilize-edit', 'templateData', array('slug' => $slug)); if ($slug === 'mobilize') { $layout = self::getPageLayout(get_the_ID()); require INC_MOBILIZE . '/includes/page_edit.php'; } }
public function setUp() { $template_files = get_page_templates(); //get all available templates file $templates_field_data = array('' => '--- Chọn ---'); //list all templates select tag //prepare fields foreach ($template_files as $name => $file) { $templates_field_data[$file] = $name; } $this->addSettingFields(array('field_id' => 'enable', 'type' => 'checkbox', 'title' => 'Kích hoạt', 'description' => 'Kích hoạt thay đổi template.'), array('field_id' => 'query_data_and', 'type' => 'hw_condition_rules', 'title' => __('Dàng buộc AND'), 'description' => 'Thêm điều kiện lọc AND.', 'repeatable' => true), array('field_id' => 'query_data_or', 'type' => 'hw_condition_rules', 'title' => __('Dàng buộc OR'), 'description' => 'Thêm điều kiện lọc OR.', 'repeatable' => true), array('field_id' => 'template', 'type' => 'select', 'title' => "Template", 'description' => 'Chọn template chuyển hướng. Chú ý: các file template khai báo tên, nằm trong thư mục theme hiện tại và có thể nằm thư mục con.', 'label' => &$templates_field_data)); if (isset($apf_fields) && count($apf_fields)) { foreach ($apf_fields as $field_setting) { $this->addSettingField($field_setting); } } // content_{page slug}_{tab slug} //add_filter( 'content_hw_templates_settings', array( $this, 'replyToInsertContents' ) ); }
public function pt_parse_query($query) { global $pagenow, $post_type; if ('edit.php' != $pagenow) { return; } switch ($post_type) { case 'post': break; case 'page': $this->templates = get_page_templates(); if (empty($this->templates)) { return; } if (!$this->is_set_template()) { return; } $meta_group = array('key' => '_wp_page_template', 'value' => $this->get_template()); set_query_var('meta_query', array($meta_group)); break; } }
/** * Retrieve page templates. * * @since 2.6.0 * * @param array $args Method parameters. * @return array|IXR_Error */ public function wp_getPageTemplates($args) { $this->escape($args); $username = $args[1]; $password = $args[2]; if (!($user = $this->login($username, $password))) { return $this->error; } if (!current_user_can('edit_pages')) { return new IXR_Error(403, __('You are not allowed access to details about this site.')); } $templates = get_page_templates(); $templates['Default'] = 'default'; return $templates; }
/** * Print out option HTML elements for the page templates drop-down. * * @since 1.5.0 * * @param string $default Optional. The template file name. Default empty. */ function page_template_dropdown($default = '') { $templates = get_page_templates(get_post()); ksort($templates); foreach (array_keys($templates) as $template) { $selected = selected($default, $templates[$template], false); echo "\n\t<option value='" . $templates[$template] . "' {$selected}>{$template}</option>"; } }
function wpc_client_hubpage_template_meta() { global $post, $wpc_client; if ('hubpage' == $post->post_type && 0 != count(get_page_templates())) { $template = get_post_meta($post->ID, '_wp_page_template', true); ?> <p><strong><?php _e('Template', WPC_CLIENT_TEXT_DOMAIN); ?> </strong></p> <label class="screen-reader-text" for="hubpage_template"><?php _e('HUB Page Template', WPC_CLIENT_TEXT_DOMAIN); ?> </label> <select name="hubpage_template" id="hubpage_template"> <option value='default'><?php _e('Default Template', WPC_CLIENT_TEXT_DOMAIN); ?> </option> <?php page_template_dropdown($template); ?> </select> <?php } }
/** * setup_default_conditions_reference function. * * @description Setup the default conditions and their information, for display when selecting conditions. * @access public * @return void */ function setup_default_conditions_reference() { $conditions = array(); $conditions_headings = array(); // Pages $conditions['pages'] = array(); $pages = get_pages(); if (count($pages) > 0) { $conditions_headings['pages'] = __('Pages', 'bean'); foreach ($pages as $k => $v) { $token = 'post-' . $v->ID; $conditions['pages'][$token] = array('label' => $v->post_title, 'description' => sprintf(__('The "%s" page', 'bean'), $v->post_title)); } } $args = array('show_ui' => true, 'public' => true, 'publicly_queryable' => true, '_builtin' => false); $post_types = get_post_types($args, 'object'); // Set certain post types that aren't allowed to have custom sidebars. $disallowed_types = array('slide'); // Make the array filterable. $disallowed_types = apply_filters('beansidebars_disallowed_post_types', $disallowed_types); if (count($post_types)) { foreach ($post_types as $k => $v) { if (in_array($k, $disallowed_types)) { unset($post_types[$k]); } } } // Add per-post support for any post type that supports it. $args = array('show_ui' => true, 'public' => true, 'publicly_queryable' => true, '_builtin' => true); $built_in_post_types = get_post_types($args, 'object'); foreach ($built_in_post_types as $k => $v) { if ($k == 'post') { $post_types[$k] = $v; break; } } foreach ($post_types as $k => $v) { if (!post_type_supports($k, 'beansidebars')) { continue; } $conditions_headings[$k] = $v->labels->name; $query_args = array('numberposts' => -1, 'post_type' => $k, 'meta_key' => '_enable_sidebar', 'meta_value' => 'yes', 'meta_compare' => '='); $posts = get_posts($query_args); if (count($posts) > 0) { foreach ($posts as $i => $j) { $conditions[$k]['post' . '-' . $j->ID] = array('label' => $j->post_title, 'description' => sprintf(__('A custom sidebar for "%s"', 'bean'), esc_attr($j->post_title))); } } } // Page Templates $conditions['templates'] = array(); $page_templates = get_page_templates(); if (count($page_templates) > 0) { $conditions_headings['templates'] = __('Page Templates', 'bean'); foreach ($page_templates as $k => $v) { $token = str_replace('.php', '', 'page-template-' . $v); $conditions['templates'][$token] = array('label' => $k, 'description' => sprintf(__('The "%s" page template', 'bean'), $k)); } } // Post Type Archives $conditions['post_types'] = array(); if (count($post_types) > 0) { $conditions_headings['post_types'] = __('Post Types', 'bean'); foreach ($post_types as $k => $v) { $token = 'post-type-archive-' . $k; if ($v->has_archive) { $conditions['post_types'][$token] = array('label' => sprintf(__('%s Posts Archive', 'bean'), $v->labels->name), 'description' => sprintf(__('The %s post type archive', 'bean'), $v->labels->name)); } } foreach ($post_types as $k => $v) { $token = 'post-type-' . $k; $conditions['post_types'][$token] = array('label' => sprintf(__('Individual %s', 'bean'), $v->labels->name), 'description' => sprintf(__('Entries in the "%s" post type', 'bean'), $v->labels->name)); } } // Taxonomies and Taxonomy Terms $conditions['taxonomies'] = array(); $args = array('public' => true, 'show_ui' => true); $taxonomies = get_taxonomies($args, 'objects'); if (count($taxonomies) > 0) { $conditions_headings['taxonomies'] = __('Taxonomy Archives', 'bean'); foreach ($taxonomies as $k => $v) { $taxonomy = $v; if ($taxonomy->public == true) { $conditions['taxonomies']['archive-' . $k] = array('label' => $taxonomy->labels->name . ' (' . $k . ')', 'description' => sprintf(__('The default "%s" archives', 'bean'), strtolower($taxonomy->labels->name))); // Setup each individual taxonomy's terms as well. $conditions_headings['taxonomy-' . $k] = $taxonomy->labels->name; $terms = get_terms($k); if (count($terms) > 0) { $conditions['taxonomy-' . $k] = array(); foreach ($terms as $i => $j) { $conditions['taxonomy-' . $k]['term-' . $j->term_id] = array('label' => $j->name, 'description' => sprintf(__('The %s %s archive', 'bean'), $j->name, strtolower($taxonomy->labels->name))); if ($k == 'category') { $conditions['taxonomy-' . $k]['in-term-' . $j->term_id] = array('label' => sprintf(__('All posts in "%s"', 'bean'), $j->name), 'description' => sprintf(__('All posts in the %s %s archive', 'bean'), $j->name, strtolower($taxonomy->labels->name))); } } } } } } $conditions_headings['hierarchy'] = __('Template Hierarchy', 'bean'); // Template Hierarchy $conditions['hierarchy']['page'] = array('label' => __('Pages', 'bean'), 'description' => __('Displayed on all pages that don\'t have a more specific widget area.', 'bean')); $conditions['hierarchy']['search'] = array('label' => __('Search Results', 'bean'), 'description' => __('Displayed on search results screens.', 'bean')); $conditions['hierarchy']['home'] = array('label' => __('Default "Your Latest Posts" Screen', 'bean'), 'description' => __('Displayed on the default "Your Latest Posts" screen.', 'bean')); $conditions['hierarchy']['front_page'] = array('label' => __('Front Page', 'bean'), 'description' => __('Displayed on any front page, regardless of the settings under the "Settings -> Reading" admin screen.', 'bean')); $conditions['hierarchy']['single'] = array('label' => __('Single Entries', 'bean'), 'description' => __('Displayed on single entries of any public post type other than "Pages".', 'bean')); $conditions['hierarchy']['archive'] = array('label' => __('All Archives', 'bean'), 'description' => __('Displayed on all archives (category, tag, taxonomy, post type, dated, author and search).', 'bean')); $conditions['hierarchy']['author'] = array('label' => __('Author Archives', 'bean'), 'description' => __('Displayed on all author archive screens (that don\'t have a more specific sidebar).', 'bean')); $conditions['hierarchy']['date'] = array('label' => __('Date Archives', 'bean'), 'description' => __('Displayed on all date archives.', 'bean')); $conditions['hierarchy']['404'] = array('label' => __('404 Error Screens', 'bean'), 'description' => __('Displayed on all 404 error screens.', 'bean')); $this->conditions_reference = (array) apply_filters('bean_conditions_reference', $conditions); $this->conditions_headings = (array) apply_filters('bean_conditions_headings', $conditions_headings); }
/** * Display page attributes form fields. * * @since 2.7.0 * * @param object $post */ function page_attributes_meta_box($post) { $post_type_object = get_post_type_object($post->post_type); if ($post_type_object->hierarchical) { $dropdown_args = array('post_type' => $post->post_type, 'exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column' => 'menu_order, post_title', 'echo' => 0); /** * Filter the arguments used to generate a Pages drop-down element. * * @since 3.3.0 * * @see wp_dropdown_pages() * * @param array $dropdown_args Array of arguments used to generate the pages drop-down. * @param WP_Post $post The current WP_Post object. */ $dropdown_args = apply_filters('page_attributes_dropdown_pages_args', $dropdown_args, $post); $pages = wp_dropdown_pages($dropdown_args); if (!empty($pages)) { ?> <p><strong><?php _e('Parent'); ?> </strong></p> <label class="screen-reader-text" for="parent_id"><?php _e('Parent'); ?> </label> <?php echo $pages; } // end empty pages check } // end hierarchical check. if ('page' == $post->post_type && 0 != count(get_page_templates($post)) && get_option('page_for_posts') != $post->ID) { $template = !empty($post->page_template) ? $post->page_template : false; ?> <p><strong><?php _e('Template'); ?> </strong><?php /** * Fires immediately after the heading inside the 'Template' section * of the 'Page Attributes' meta box. * * @since 4.4.0 * * @param string $template The template used for the current post. * @param WP_Post $post The current post. */ do_action('page_attributes_meta_box_template', $template, $post); ?> </p> <label class="screen-reader-text" for="page_template"><?php _e('Page Template'); ?> </label><select name="page_template" id="page_template"> <?php /** * Filter the title of the default page template displayed in the drop-down. * * @since 4.1.0 * * @param string $label The display value for the default page template title. * @param string $context Where the option label is displayed. Possible values * include 'meta-box' or 'quick-edit'. */ $default_title = apply_filters('default_page_template_title', __('Default Template'), 'meta-box'); ?> <option value="default"><?php echo esc_html($default_title); ?> </option> <?php page_template_dropdown($template); ?> </select> <?php } ?> <p><strong><?php _e('Order'); ?> </strong></p> <p><label class="screen-reader-text" for="menu_order"><?php _e('Order'); ?> </label><input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr($post->menu_order); ?> " /></p> <?php if ('page' == $post->post_type && get_current_screen()->get_help_tabs()) { ?> <p><?php _e('Need help? Use the Help tab in the upper right of your screen.'); ?> </p> <?php } }
/** * Insert a post. * * If the $postarr parameter has 'ID' set to a value, then post will be updated. * * You can set the post date manually, but setting the values for 'post_date' * and 'post_date_gmt' keys. You can close the comments or open the comments by * setting the value for 'comment_status' key. * * The defaults for the parameter $postarr are: * 'post_status' - Default is 'draft'. * 'post_type' - Default is 'post'. * 'post_author' - Default is current user ID ($user_ID). The ID of the user who added the post. * 'ping_status' - Default is the value in 'default_ping_status' option. * Whether the attachment can accept pings. * 'post_parent' - Default is 0. Set this for the post it belongs to, if any. * 'menu_order' - Default is 0. The order it is displayed. * 'to_ping' - Whether to ping. * 'pinged' - Default is empty string. * 'post_password' - Default is empty string. The password to access the attachment. * 'guid' - Global Unique ID for referencing the attachment. * 'post_content_filtered' - Post content filtered. * 'post_excerpt' - Post excerpt. * * @since 1.0.0 * @uses $wpdb * @uses $wp_rewrite * @uses $user_ID * @uses do_action() Calls 'pre_post_update' on post ID if this is an update. * @uses do_action() Calls 'edit_post' action on post ID and post data if this is an update. * @uses do_action() Calls 'save_post' and 'wp_insert_post' on post id and post data just before returning. * @uses apply_filters() Calls 'wp_insert_post_data' passing $data, $postarr prior to database update or insert. * @uses wp_transition_post_status() * * @param array $postarr Elements that make up post to insert. * @param bool $wp_error Optional. Allow return of WP_Error on failure. * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success. */ function wp_insert_post($postarr, $wp_error = false) { global $wpdb, $wp_rewrite, $user_ID; $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID, 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'post_content' => '', 'post_title' => ''); $postarr = wp_parse_args($postarr, $defaults); $postarr = sanitize_post($postarr, 'db'); // export array as variables extract($postarr, EXTR_SKIP); // Are we updating or creating? $update = false; if (!empty($ID)) { $update = true; $previous_status = get_post_field('post_status', $ID); } else { $previous_status = 'new'; } if ('' == $post_content && '' == $post_title && '' == $post_excerpt && 'attachment' != $post_type) { if ($wp_error) { return new WP_Error('empty_content', __('Content, title, and excerpt are empty.')); } else { return 0; } } if (empty($post_type)) { $post_type = 'post'; } if (empty($post_status)) { $post_status = 'draft'; } if (!empty($post_category)) { $post_category = array_filter($post_category); } // Filter out empty terms // Make sure we set a valid category. if (empty($post_category) || 0 == count($post_category) || !is_array($post_category)) { // 'post' requires at least one category. if ('post' == $post_type && 'auto-draft' != $post_status) { $post_category = array(get_option('default_category')); } else { $post_category = array(); } } if (empty($post_author)) { $post_author = $user_ID; } $post_ID = 0; // Get the post ID and GUID if ($update) { $post_ID = (int) $ID; $guid = get_post_field('guid', $post_ID); $post_before = get_post($post_ID); } // Don't allow contributors to set to set the post slug for pending review posts if ('pending' == $post_status && !current_user_can('publish_posts')) { $post_name = ''; } // Create a valid post name. Drafts and pending posts are allowed to have an empty // post name. if (empty($post_name)) { if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) { $post_name = sanitize_title($post_title); } else { $post_name = ''; } } else { $post_name = sanitize_title($post_name); } // If the post date is empty (due to having been new or a draft) and status is not 'draft' or 'pending', set date to now if (empty($post_date) || '0000-00-00 00:00:00' == $post_date) { $post_date = current_time('mysql'); } if (empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt) { if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) { $post_date_gmt = get_gmt_from_date($post_date); } else { $post_date_gmt = '0000-00-00 00:00:00'; } } if ($update || '0000-00-00 00:00:00' == $post_date) { $post_modified = current_time('mysql'); $post_modified_gmt = current_time('mysql', 1); } else { $post_modified = $post_date; $post_modified_gmt = $post_date_gmt; } if ('publish' == $post_status) { $now = gmdate('Y-m-d H:i:59'); if (mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false)) { $post_status = 'future'; } } elseif ('future' == $post_status) { $now = gmdate('Y-m-d H:i:59'); if (mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false)) { $post_status = 'publish'; } } if (empty($comment_status)) { if ($update) { $comment_status = 'closed'; } else { $comment_status = get_option('default_comment_status'); } } if (empty($ping_status)) { $ping_status = get_option('default_ping_status'); } if (isset($to_ping)) { $to_ping = preg_replace('|\\s+|', "\n", $to_ping); } else { $to_ping = ''; } if (!isset($pinged)) { $pinged = ''; } if (isset($post_parent)) { $post_parent = (int) $post_parent; } else { $post_parent = 0; } // Check the post_parent to see if it will cause a hierarchy loop $post_parent = apply_filters('wp_insert_post_parent', $post_parent, $post_ID, compact(array_keys($postarr)), $postarr); if (isset($menu_order)) { $menu_order = (int) $menu_order; } else { $menu_order = 0; } if (!isset($post_password) || 'private' == $post_status) { $post_password = ''; } $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); // expected_slashed (everything!) $data = compact(array('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid')); $data = apply_filters('wp_insert_post_data', $data, $postarr); $data = stripslashes_deep($data); $where = array('ID' => $post_ID); if ($update) { do_action('pre_post_update', $post_ID); if (false === $wpdb->update($wpdb->posts, $data, $where)) { if ($wp_error) { return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error); } else { return 0; } } } else { if (isset($post_mime_type)) { $data['post_mime_type'] = stripslashes($post_mime_type); } // This isn't in the update // If there is a suggested ID, use it if not already present if (!empty($import_id)) { $import_id = (int) $import_id; if (!$wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE ID = %d", $import_id))) { $data['ID'] = $import_id; } } if (false === $wpdb->insert($wpdb->posts, $data)) { if ($wp_error) { return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error); } else { return 0; } } $post_ID = (int) $wpdb->insert_id; // use the newly generated $post_ID $where = array('ID' => $post_ID); } if (empty($data['post_name']) && !in_array($data['post_status'], array('draft', 'pending', 'auto-draft'))) { $data['post_name'] = sanitize_title($data['post_title'], $post_ID); $wpdb->update($wpdb->posts, array('post_name' => $data['post_name']), $where); } if (is_object_in_taxonomy($post_type, 'category')) { wp_set_post_categories($post_ID, $post_category); } if (isset($tags_input) && is_object_in_taxonomy($post_type, 'post_tag')) { wp_set_post_tags($post_ID, $tags_input); } // new-style support for all custom taxonomies if (!empty($tax_input)) { foreach ($tax_input as $taxonomy => $tags) { $taxonomy_obj = get_taxonomy($taxonomy); if (is_array($tags)) { // array = hierarchical, string = non-hierarchical. $tags = array_filter($tags); } if (current_user_can($taxonomy_obj->cap->assign_terms)) { wp_set_post_terms($post_ID, $tags, $taxonomy); } } } $current_guid = get_post_field('guid', $post_ID); if ('page' == $data['post_type']) { clean_page_cache($post_ID); } else { clean_post_cache($post_ID); } // Set GUID if (!$update && '' == $current_guid) { $wpdb->update($wpdb->posts, array('guid' => get_permalink($post_ID)), $where); } $post = get_post($post_ID); if (!empty($page_template) && 'page' == $data['post_type']) { $post->page_template = $page_template; $page_templates = get_page_templates(); if ('default' != $page_template && !in_array($page_template, $page_templates)) { if ($wp_error) { return new WP_Error('invalid_page_template', __('The page template is invalid.')); } else { return 0; } } update_post_meta($post_ID, '_wp_page_template', $page_template); } wp_transition_post_status($data['post_status'], $previous_status, $post); if ($update) { do_action('edit_post', $post_ID, $post); $post_after = get_post($post_ID); do_action('post_updated', $post_ID, $post_after, $post_before); } do_action('save_post', $post_ID, $post); do_action('wp_insert_post', $post_ID, $post); return $post_ID; }
function page_template_dropdown($default = '') { $templates = get_page_templates(); foreach (array_keys($templates) as $template) { if ($default == $templates[$template]) { $selected = " selected='selected'"; } else { $selected = ''; } echo "\n\t<option value='" . $templates[$template] . "' {$selected}>{$template}</option>"; } }
function render_location_value($options) { // vars $options = wp_parse_args($options, array('group_id' => 0, 'rule_id' => 0, 'value' => null, 'param' => null)); // vars $choices = array(); // some case's have the same outcome if ($options['param'] == "page_parent") { $options['param'] = "page"; } switch ($options['param']) { /* * Basic */ case "post_type": // all post types except attachment $exclude = array('attachment'); $choices = acf_get_post_types($exclude); $choices = acf_get_pretty_post_types($choices); break; case "user_type": global $wp_roles; $choices = $wp_roles->get_names(); if (is_multisite()) { $choices['super_admin'] = __('Super Admin'); } break; /* * Post */ /* * Post */ case "post": // get post types $exclude = array('page', 'attachment'); $post_types = acf_get_post_types($exclude); // get posts grouped by post type $groups = acf_get_posts(array('post_type' => $post_types)); if (!empty($groups)) { foreach (array_keys($groups) as $group_title) { // vars $posts = acf_extract_var($groups, $group_title); // override post data foreach (array_keys($posts) as $post_id) { // update $posts[$post_id] = acf_get_post_title($posts[$post_id]); } // append to $choices $choices[$group_title] = $posts; } } break; case "post_category": $terms = acf_get_taxonomy_terms('category'); if (!empty($terms)) { $choices = array_pop($terms); } break; case "post_format": $choices = get_post_format_strings(); break; case "post_status": $choices = array('publish' => __('Publish', 'acf'), 'pending' => __('Pending Review', 'acf'), 'draft' => __('Draft', 'acf'), 'future' => __('Future', 'acf'), 'private' => __('Private', 'acf'), 'inherit' => __('Revision', 'acf'), 'trash' => __('Trash', 'acf')); break; case "post_taxonomy": $choices = acf_get_taxonomy_terms(); // unset post_format if (isset($choices['post_format'])) { unset($choices['post_format']); } break; /* * Page */ /* * Page */ case "page": // get posts grouped by post type $groups = acf_get_posts(array('post_type' => 'page')); if (!empty($groups)) { foreach (array_keys($groups) as $group_title) { // vars $posts = acf_extract_var($groups, $group_title); // override post data foreach (array_keys($posts) as $post_id) { // update $posts[$post_id] = acf_get_post_title($posts[$post_id]); } // append to $choices $choices = $posts; } } break; case "page_type": $choices = array('front_page' => __("Front Page", 'acf'), 'posts_page' => __("Posts Page", 'acf'), 'top_level' => __("Top Level Page (parent of 0)", 'acf'), 'parent' => __("Parent Page (has children)", 'acf'), 'child' => __("Child Page (has parent)", 'acf')); break; case "page_parent": // refer to "page" break; case "page_template": $choices = array('default' => __("Default Template", 'acf')); $templates = get_page_templates(); foreach ($templates as $k => $v) { $choices[$v] = $k; } break; /* * User */ /* * User */ case "user_role": global $wp_roles; $choices = array_merge(array('all' => __('All', 'acf')), $wp_roles->get_names()); break; case "user_form": $choices = array('all' => __('All', 'acf'), 'edit' => __('Add / Edit', 'acf'), 'register' => __('Register', 'acf')); break; /* * Forms */ /* * Forms */ case "attachment": $choices = array('all' => __('All', 'acf')); break; case "taxonomy": $choices = array_merge(array('all' => __('All', 'acf')), acf_get_taxonomies()); // unset post_format if (isset($choices['post_format'])) { unset($choices['post_format']); } break; case "comment": $choices = array('all' => __('All', 'acf')); break; case "widget": global $wp_widget_factory; $choices = array('all' => __('All', 'acf')); if (!empty($wp_widget_factory->widgets)) { foreach ($wp_widget_factory->widgets as $widget) { $choices[$widget->id_base] = $widget->name; } } break; } // allow custom location rules $choices = apply_filters('acf/location/rule_values/' . $options['param'], $choices); // create field acf_render_field(array('type' => 'select', 'prefix' => "acf_field_group[location][{$options['group_id']}][{$options['rule_id']}]", 'name' => 'value', 'value' => $options['value'], 'choices' => $choices)); }
/** * Display page attributes form fields. * * @since 2.7.0 * * @param object $post */ function page_attributes_meta_box($post) { $post_type_object = get_post_type_object($post->post_type); if ($post_type_object->hierarchical) { $dropdown_args = array('post_type' => $post->post_type, 'exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column' => 'menu_order, post_title', 'echo' => 0); $dropdown_args = apply_filters('page_attributes_dropdown_pages_args', $dropdown_args, $post); $pages = wp_dropdown_pages($dropdown_args); if (!empty($pages)) { ?> <p><strong><?php _e('Parent'); ?> </strong></p> <label class="screen-reader-text" for="parent_id"><?php _e('Parent'); ?> </label> <?php echo $pages; } // end empty pages check } // end hierarchical check. if ('page' == $post->post_type && 0 != count(get_page_templates())) { $template = !empty($post->page_template) ? $post->page_template : false; ?> <p><strong><?php _e('Template'); ?> </strong></p> <label class="screen-reader-text" for="page_template"><?php _e('Page Template'); ?> </label><select name="page_template" id="page_template"> <option value='default'><?php _e('Default Template'); ?> </option> <?php page_template_dropdown($template); ?> </select> <?php } ?> <p><strong><?php _e('Order'); ?> </strong></p> <p><label class="screen-reader-text" for="menu_order"><?php _e('Order'); ?> </label><input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr($post->menu_order); ?> " /></p> <p><?php if ('page' == $post->post_type) { _e('Need help? Use the Help tab in the upper right of your screen.'); } ?> </p> <?php }
/** * Manage custom column for Post Types. * * @since 1.0 */ public function manage_posts_column_value($column_name, $post_id) { $type = $column_name; // Check for taxonomies, such as column-taxonomy-[taxname] if (strpos($type, 'column-taxonomy-') !== false) { $type = 'column-taxonomy'; } // Check for custom fields, such as column-meta-[customfieldname] if ($this->is_column_meta($type)) { $type = 'column-post-meta'; } // Hook do_action('cpac-manage-posts-column', $type, $column_name, $post_id); // Switch Types $result = ''; switch ($type) { // Post ID case "column-postid": $result = $post_id; break; // Excerpt // Excerpt case "column-excerpt": $result = $this->get_post_excerpt($post_id); break; // Featured Image // Featured Image case "column-featured_image": if (function_exists('has_post_thumbnail') && has_post_thumbnail($post_id)) { $result = get_the_post_thumbnail($post_id, $this->thumbnail_size); } break; // Sticky Post // Sticky Post case "column-sticky": if (is_sticky($post_id)) { $result = $this->get_asset_image('checkmark.png'); } break; // Order // Order case "column-order": $result = get_post_field('menu_order', $post_id); break; // Post Formats // Post Formats case "column-post_formats": $result = get_post_format($post_id); break; // Page template // Page template case "column-page-template": // file name $page_template = get_post_meta($post_id, '_wp_page_template', true); // get template nice name $result = array_search($page_template, get_page_templates()); break; // Slug // Slug case "column-page-slug": $result = get_post($post_id)->post_name; break; // Slug // Slug case "column-word-count": $result = str_word_count($this->strip_trim(get_post($post_id)->post_content)); break; // Taxonomy // Taxonomy case "column-taxonomy": $tax = str_replace('column-taxonomy-', '', $column_name); $tags = get_the_terms($post_id, $tax); $tarr = array(); // for post formats we will display standard instead of empty if ($tax == 'post_format' && empty($tags)) { $result = __('Standard'); } elseif (!empty($tags)) { $post_type = get_post_type($post_id); foreach ($tags as $tag) { // sanatize title if (isset($tag->term_id)) { $tax_title = esc_html(sanitize_term_field('name', $tag->name, $tag->term_id, $tag->taxonomy, 'edit')); $tarr[] = "<a href='edit.php?post_type={$post_type}&{$tag->taxonomy}={$tag->slug}'>{$tax_title}</a>"; } } $result = implode(', ', $tarr); } break; // Custom Field // Custom Field case "column-post-meta": $result = $this->get_column_value_custom_field($post_id, $column_name, 'post'); break; // Attachment // Attachment case "column-attachment": $result = $this->get_column_value_attachments($post_id); break; // Attachment count // Attachment count case "column-attachment-count": $result = count($this->get_attachment_ids($post_id)); break; // Roles // Roles case "column-roles": $user_id = get_post($post_id)->post_author; $userdata = get_userdata($user_id); if (!empty($userdata->roles[0])) { $result = implode(', ', $userdata->roles); } break; // Post status // Post status case "column-status": $p = get_post($post_id); $result = $this->get_post_status_friendly_name($p->post_status); if ($p->post_status == 'future') { $result = $result . " <p class='description'>" . date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($p->post_date)) . "</p>"; } break; // Post comment status // Post comment status case "column-comment-status": $p = get_post($post_id); $result = $this->get_asset_image('no.png', $p->comment_status); if ($p->comment_status == 'open') { $result = $this->get_asset_image('checkmark.png', $p->comment_status); } break; // Post ping status // Post ping status case "column-ping-status": $p = get_post($post_id); $result = $this->get_asset_image('no.png', $p->ping_status); if ($p->ping_status == 'open') { $result = $this->get_asset_image('checkmark.png', $p->ping_status); } break; // Post actions ( delete, edit etc. ) // Post actions ( delete, edit etc. ) case "column-actions": $result = $this->get_column_value_actions($post_id); break; // Post Last modified // Post Last modified case "column-modified": $p = get_post($post_id); $result = $this->get_date($p->post_modified) . ' ' . $this->get_time($p->post_modified); break; // Post Comment count // Post Comment count case "column-comment-count": $result = WP_List_Table::comments_bubble($post_id, get_pending_comments_num($post_id)); $result .= $this->get_comment_count_details($post_id); break; // Author Name // Author Name case "column-author-name": $result = $this->get_column_value_authorname($post_id, $column_name); break; // Before More Tag // Before More Tag case "column-before-moretag": $p = get_post($post_id); $extended = get_extended($p->post_content); if (!empty($extended['extended'])) { $result = $this->get_shortened_string($extended['main'], $this->excerpt_length); } break; default: $result = ''; } // Filter for customizing the result output apply_filters('cpac-posts-column-result', $result, $type, $column_name, $post_id); echo $result; }
function ajax_acf_location($options = array()) { // defaults $defaults = array('key' => null, 'value' => null, 'param' => null); // Is AJAX call? if (isset($_POST['action']) && $_POST['action'] == "acf_location") { $options = array_merge($defaults, $_POST); } else { $options = array_merge($defaults, $options); } // some case's have the same outcome if ($options['param'] == "page_parent") { $options['param'] = "page"; } $choices = array(); $optgroup = false; switch ($options['param']) { case "post_type": $choices = get_post_types(array('public' => true)); unset($choices['attachment']); break; case "page": $pages = get_pages(array('numberposts' => -1, 'post_type' => 'page', 'sort_column' => 'menu_order', 'order' => 'ASC', 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'), 'suppress_filters' => false)); foreach ($pages as $page) { $title = ''; $ancestors = get_ancestors($page->ID, 'page'); if ($ancestors) { foreach ($ancestors as $a) { $title .= '- '; } } $title .= apply_filters('the_title', $page->post_title, $page->ID); // status if ($page->post_status != "publish") { $title .= " ({$page->post_status})"; } $choices[$page->ID] = $title; } break; case "page_type": $choices = array('parent' => __("Parent Page", 'acf'), 'child' => __("Child Page", 'acf')); break; case "page_template": $choices = array('default' => __("Default Template", 'acf')); $templates = get_page_templates(); foreach ($templates as $k => $v) { $choices[$v] = $k; } break; case "post": $posts = get_posts(array('numberposts' => '-1', 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'), 'suppress_filters' => false)); foreach ($posts as $post) { $title = apply_filters('the_title', $post->post_title, $post->ID); // status if ($post->post_status != "publish") { $title .= " ({$post->post_status})"; } $choices[$post->ID] = $title; } break; case "post_category": $category_ids = get_all_category_ids(); foreach ($category_ids as $cat_id) { $cat_name = get_cat_name($cat_id); $choices[$cat_id] = $cat_name; } break; case "post_format": $choices = get_post_format_strings(); break; case "user_type": global $wp_roles; $choices = $wp_roles->get_names(); break; case "options_page": $choices = array(__('Options', 'acf') => __('Options', 'acf')); $custom = apply_filters('acf_register_options_page', array()); if (!empty($custom)) { $choices = array(); foreach ($custom as $c) { $choices[$c['slug']] = $c['title']; } } break; case "taxonomy": $choices = $this->parent->get_taxonomies_for_select(array('simple_value' => true)); $optgroup = true; break; case "ef_taxonomy": $choices = array('all' => __('All', 'acf')); $taxonomies = get_taxonomies(array('public' => true), 'objects'); foreach ($taxonomies as $taxonomy) { $choices[$taxonomy->name] = $taxonomy->labels->name; } // unset post_format (why is this a public taxonomy?) if (isset($choices['post_format'])) { unset($choices['post_format']); } break; case "ef_user": global $wp_roles; $choices = array_merge(array('all' => __('All', 'acf')), $wp_roles->get_names()); break; case "ef_media": $choices = array('all' => __('All', 'acf')); break; } $this->parent->create_field(array('type' => 'select', 'name' => 'location[rules][' . $options['key'] . '][value]', 'value' => $options['value'], 'choices' => $choices, 'optgroup' => $optgroup)); // ajax? if (isset($_POST['action']) && $_POST['action'] == "acf_location") { die; } }