function url_shortcode($atts) { // Attributes extract(shortcode_atts(array('type' => '', 'id' => '0', 'path' => '', 'title' => '', 'action' => '', 'class' => ''), $atts)); if (!$id && !$path && !$title && !$action) { return home_url(); } else { $page_id = 0; if ($id && is_numeric($id)) { $page_id = $id; } if ($path != '') { $page_id = get_page_by_path($path); } if ($title != '') { $page_id = get_page_by_title($title); } if ($action != '') { if ($action == 'logout') { return wp_logout_url(); } } if ($page_id) { return get_page_link($page_id); } else { return null; } } }
/** * Gets a WordPress® post by path; instead of by ID. * * @param string $path A URL path (ex: `/sample-page/`, `/sample-page`, `sample-page`). * This also works with sub-pages (ex: `/parent-page/sub-page/`). * Also with post type prefixes (ex: `/post/hello-world/`). * Also with pagination (ex: `/post/hello-world/page/2`). * * @param array $exclude_types Optional. Defaults to `array('revision', 'nav_menu_item')`. * We will NOT search for these post types. Pass an empty array to search all post types. * Important to note... it is NOT possible to exclude the `attachment` type; * because {@link \get_page_by_path()} always searches this type. * * @return null|\WP_Post A WP_Post object instance if found; else NULL. * * @throws exception If invalid types are passed through arguments list. * * @see http://codex.wordpress.org/Function_Reference/get_page_by_path * NOTE: This supports MORE than just pages; even though the function name implies otherwise. */ public function by_path($path, $exclude_types = array('revision', 'nav_menu_item')) { $this->check_arg_types('string', 'array', func_get_args()); $path = trim($path, '/'); // Trim all slashes. $path = preg_replace($this->©url->regex_wp_pagination_page(), '', $path); if ($path && $path !== '/') { foreach (get_post_types() as $_type) { if (!in_array($_type, $exclude_types, TRUE)) { $_type_slug = $_type; // Default slug. $_type_specs = get_post_type_object($_type); if ($this->©array->is_not_empty($_type_specs->rewrite)) { if ($this->©string->is_not_empty($_type_specs->rewrite['slug'])) { $_type_slug = $_type_specs->rewrite['slug']; } } if ($_path = preg_replace('/^' . preg_quote($_type_slug, '/') . '\\//', '', $path)) { if ($post = get_page_by_path($_path, OBJECT, $_type)) { return $post; } } } } } unset($_type, $_type_specs, $_type_slug); return NULL; // Default return value. }
function form($instance) { $home = get_page_by_path('home'); $home_text = get_post_meta($home->ID, 'home_text_widget', true); if (empty($home_text)) { $home_text['home_text_title'] = __('Titel'); $home_text['home_text_body'] = ''; } ?> <p> <label for="home_text_title">Titel</label> <input id="home_text_title" name="home_text_title" value="<?php echo $home_text['home_text_title']; ?> " style="width:100%;" /> </p> <p> <label for="home_text_body">Body</label> <textarea id="home_text_body" name="home_text_body" style="width:100%;height:80px;"><?php echo $home_text['home_text_body']; ?> </textarea> </p> <?php }
function print_sibiling_pages($post) { $slug_parts = explode('-', $post->post_name); if (count($slug_parts) != 2) { return; } $page_num = intval($slug_parts[1]); if ($page_num <= 0) { return; } echo '<div class="story-pageing">'; if ($page_num > 1) { $back_slug = $slug_parts[0] . '-' . ($page_num - 1); $back_page = get_posts(array('name' => $back_slug, 'post_type' => 'page')); if (count($back_page) > 0) { echo '<div class="story-back"><a href="' . get_permalink(get_page_by_path($back_slug)) . '">Read Previous Story</a></div>'; } } $next_slug = $slug_parts[0] . '-' . ($page_num + 1); $next_page = get_posts(array('name' => $next_slug, 'post_type' => 'page')); if (count($next_page) > 0) { echo '<div class="story-next"><a href="' . get_permalink(get_page_by_path($next_slug)) . '">Read Next Story</a></div>'; } echo '</div>'; }
/** * ユーザー登録処理 * */ public function registerUser() { // 新規ユーザーデータを取得する $this->user = $this->clearUser(); if (isset($_POST['nonce'])) { // エラーなら処理を中止する if ($this->errcode = $this->_illegalInput()) { return; } if ($_POST['action'] === 'confirm' && $this->_normalize()) { // ユーザー新規登録 if (!$this->_newUser()) { $this->errcode = 'FAILED_INSERT'; return; } // 登録完了メール送信 if (!$this->_sendMail()) { $this->errcode = 'FAILED_SENDING'; return; } // 登録完了リダイレクト表示 $url = get_permalink(get_page_by_path(self::PAGE_THANKS)); $redirect = add_query_arg(array('action' => 'registered', 'nonce' => wp_create_nonce(__CLASS__)), $url); wp_redirect($redirect); exit; } } }
/** * Creates the shortcode for the plugin. * * @since 2.0.0 * * @global object $post The current post object. * * @param array $atts Array of shortcode attributes. * @return string The optin output. */ public function shortcode($atts) { global $post; $optin_id = false; if (isset($atts['id'])) { $optin_id = (int) $atts['id']; } else { if (isset($atts['slug'])) { $optin = get_page_by_path($atts['slug'], OBJECT, 'optin'); if ($optin) { $optin_id = $optin->ID; } } else { // A custom attribute must have been passed. Allow it to be filtered to grab the optin ID from a custom source. $optin_id = apply_filters('optin_monster_custom_optin_id', false, $atts, $post); } } // Allow the optin ID to be filtered before it is stored and used to create the optin output. $optin_id = apply_filters('optin_monster_pre_optin_id', $optin_id, $atts, $post); // If there is no optin, do nothing. if (!$optin_id) { return false; } // If we are in a preview state, the optin needs to match the one requested, otherwise return false. if (Optin_Monster_Output::get_instance()->is_preview()) { if (Optin_Monster_Output::get_instance()->optin_id && Optin_Monster_Output::get_instance()->optin_id !== $optin_id || !empty(Optin_Monster_Output::get_instance()->data[$optin_id])) { return false; } } // Return the output. return Optin_Monster_Output::get_instance()->get_optin_monster($optin_id); }
/** * Install WP Job Manager */ public static function install() { global $wpdb; self::init_user_roles(); self::default_terms(); self::schedule_cron(); // Redirect to setup screen for new installs if (!get_option('wp_job_manager_version')) { set_transient('_job_manager_activation_redirect', 1, HOUR_IN_SECONDS); } // Update featured posts ordering if (version_compare(get_option('wp_job_manager_version', JOB_MANAGER_VERSION), '1.22.0', '<')) { $wpdb->query("UPDATE {$wpdb->posts} p SET p.menu_order = 0 WHERE p.post_type='job_listing';"); $wpdb->query("UPDATE {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id SET p.menu_order = -1 WHERE pm.meta_key = '_featured' AND pm.meta_value='1' AND p.post_type='job_listing';"); } // Update legacy options if (false === get_option('job_manager_submit_job_form_page_id', false) && get_option('job_manager_submit_page_slug')) { $page_id = get_page_by_path(get_option('job_manager_submit_page_slug'))->ID; update_option('job_manager_submit_job_form_page_id', $page_id); } if (false === get_option('job_manager_job_dashboard_page_id', false) && get_option('job_manager_job_dashboard_page_slug')) { $page_id = get_page_by_path(get_option('job_manager_job_dashboard_page_slug'))->ID; update_option('job_manager_job_dashboard_page_id', $page_id); } delete_transient('wp_job_manager_addons_html'); update_option('wp_job_manager_version', JOB_MANAGER_VERSION); }
/** * __construct function. */ public function __construct() { // Define constants define('JOB_MANAGER_ALERTS_VERSION', '1.3.14'); define('JOB_MANAGER_ALERTS_PLUGIN_DIR', untrailingslashit(plugin_dir_path(__FILE__))); define('JOB_MANAGER_ALERTS_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); // Includes include 'includes/class-wp-job-manager-alerts-shortcodes.php'; include 'includes/class-wp-job-manager-alerts-post-types.php'; include 'includes/class-wp-job-manager-alerts-notifier.php'; // Init classes $this->post_types = new WP_Job_Manager_Alerts_Post_Types(); // Add actions add_action('init', array($this, 'init'), 12); add_action('wp_enqueue_scripts', array($this, 'frontend_scripts')); add_filter('job_manager_settings', array($this, 'settings')); add_filter('job_manager_job_filters_showing_jobs_links', array($this, 'alert_link'), 10, 2); add_action('single_job_listing_end', array($this, 'single_alert_link')); // Update legacy options if (false === get_option('job_manager_alerts_page_id', false) && get_option('job_manager_alerts_page_slug')) { $page_id = get_page_by_path(get_option('job_manager_alerts_page_slug'))->ID; update_option('job_manager_alerts_page_id', $page_id); } // Init updates $this->init_updates(__FILE__); }
public function embedPatreonContent($args) { /* example shortcode [patreon_content slug="test-example"] /* check if shortcode has slug parameter */ if (isset($args['slug'])) { /* get patreon-content post with matching url slug */ $patreon_content = get_page_by_path($args['slug'], OBJECT, 'patreon-content'); if ($patreon_content == false) { return 'Patreon content not found.'; } $patreon_level = get_post_meta($patreon_content->ID, 'patreon-level', true); if ($patreon_level == 0) { return $patreon_content->post_content; } $user_patronage = Patreon_Wordpress::getUserPatronage(); if ($user_patronage != false) { if (is_numeric($patreon_level) && $user_patronage >= $patreon_level * 100) { return $patreon_content->post_content; } } if (isset($args['youtube_id']) && isset($args['youtube_width']) && is_numeric($args['youtube_width']) && isset($args['youtube_height']) && is_numeric($args['youtube_height'])) { return '<iframe width="' . $args['youtube_width'] . '" height="' . $args['youtube_height'] . '" src="https://www.youtube.com/embed/' . $args['youtube_id'] . '?rel=0&controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe>'; } else { return self::displayPatreonCampaignBanner(); } } }
function getArchive() { $page = get_page_by_path($_SERVER['REQUEST_URI']); if (!is_null($page)) { return !empty($title = trim(\get_post_meta($page->ID, 'quan_meta_title', true))) ? $title : ''; } }
function form($instance) { $contact = get_page_by_path('contact'); $contact_info = get_post_meta($contact->ID, 'contact_info_widget', true); if (empty($contact_info)) { $contact_info['contact_info_title'] = __('Titel'); $contact_info['contact_info_body'] = ''; } ?> <p> <label for="contact_info_title">Titel</label> <input id="contact_info_title" name="contact_info_title" value="<?php echo $contact_info['contact_info_title']; ?> " style="width:100%;" /> </p> <p> <label for="contact_info_body">Body</label> <textarea id="contact_info_body" name="contact_info_body" style="width:100%;height:80px;"><?php echo $contact_info['contact_info_body']; ?> </textarea> </p> <?php }
function getArchive() { $page = get_page_by_path($_SERVER['REQUEST_URI']); if (!is_null($page)) { return !empty($description = trim(\get_post_meta($page->ID, 'quan_meta_description', true))) ? $description : false; } }
public function index($category_slug, $post_slug) { $post = get_page_by_path($post_slug, OBJECT, 'post'); $post = new TimberPost($post->ID); $canonical_url = $post->catfish_importer_url; return $this->client->getSubmissionStatus(get_field('instant_articles_status_id', $post)); }
function old_wp_login_redirect() { if (!is_user_logged_in() && in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')) && get_page_by_path('login') != NULL) { wp_redirect(get_site_url() . '/login/', $status); die; } }
public static function add_rewrite_rules($rules) { //Get taxonomies $taxonomies = get_taxonomies(); $blog_prefix = ''; $endpoint = Slash_Edit::get_instance()->get_endpoint(); if (is_multisite() && !is_subdomain_install() && is_main_site()) { /* stolen from /wp-admin/options-permalink.php */ $blog_prefix = 'blog/'; } $exclude = array('category', 'post_tag', 'nav_menu', 'link_category', 'post_format'); foreach ($taxonomies as $key => $taxonomy) { if (in_array($key, $exclude)) { continue; } $rules["{$blog_prefix}{$key}/([^/]+)/{$endpoint}(/(.*))?/?\$"] = 'index.php?' . $key . '=$matches[1]&' . $endpoint . '=$matches[3]'; } //Add home_url/edit to rewrites $add_frontpage_edit_rules = false; if (!get_page_by_path($endpoint)) { $add_frontpage_edit_rules = true; } else { $page = get_page_by_path($endpoint); if (is_a($page, 'WP_Post') && $page->post_status != 'publish') { $add_frontpage_edit_rules = true; } } if ($add_frontpage_edit_rules) { $edit_array_rule = array("{$endpoint}/?\$" => 'index.php?' . $endpoint . '=frontpage'); $rules = $edit_array_rule + $rules; } return $rules; }
function demo_content_starterkit_frontpage() { $page = 'wine'; $slug = get_page_by_path('home-pages/' . $page) ? 'home-pages/' . $page : $page; return $slug; // slug }
protected function pageParam($params) { global $post; $name = array_shift($params); $path = get_page_uri($post->ID) . '/' . $name; return get_page_by_path($path); }
/** * Check if the path requested matches an assigned index page. * * Also checks for date and pagination parameters. * * @since 1.2.0 Added check to make sure post type currently exists. * @since 1.0.0 * * @param WP $wp The WP request object. */ public static function handle_request(\WP $wp) { $qv =& $wp->query_vars; // Abort if a pagename wasn't matched at all if (!isset($qv['pagename'])) { return; } // Build a RegExp to capture a page with date/paged arguments $pattern = '(.+?)' . '(?:/([0-9]{4})' . '(?:/([0-9]{2})' . '(?:/([0-9]{2}))?' . ')?' . ')?' . '(?:/page/([0-9]+))?' . '/?$'; // Proceed if the pattern checks out if (preg_match("#{$pattern}#", $wp->request, $matches)) { // Get the page using match 1 (pagename) $page = get_page_by_path($matches[1]); // Abort if no page is found if (is_null($page)) { return; } // Get the post type, and validate that it exists if (($post_type = Registry::is_index_page($page->ID)) && post_type_exists($post_type)) { // Modify the request into a post type archive instead $qv['post_type'] = $post_type; list(, , $qv['year'], $qv['monthnum'], $qv['day'], $qv['paged']) = array_pad($matches, 6, null); // Make sure these are unset unset($qv['pagename']); unset($qv['page']); unset($qv['name']); } } }
function clear_menu_from_old_woo_pages() { $locations = get_nav_menu_locations(); $logout = get_page_by_path('my-account/logout'); $parent = get_page_by_path('my-account'); $permalink = get_option('permalink_structure'); $pages_deleted = array(get_option('woocommerce_pay_page_id'), get_option('woocommerce_thanks_page_id'), get_option('woocommerce_view_order_page_id'), get_option('woocommerce_view_order_page_id'), get_option('woocommerce_change_password_page_id'), get_option('woocommerce_edit_address_page_id'), get_option('woocommerce_lost_password_page_id')); foreach ((array) $locations as $name => $menu_ID) { $items = wp_get_nav_menu_items($menu_ID); foreach ((array) $items as $item) { if (!is_null($logout) && !is_null($parent) && $item->object_id == $logout->ID) { update_post_meta($item->ID, '_menu_item_object', 'custom'); update_post_meta($item->ID, '_menu_item_type', 'custom'); if ($permalink == '') { $new_url = get_permalink($parent->ID) . '&customer-logout'; } else { wp_update_post(array('ID' => $logout->ID, 'post_name' => 'customer-logout')); $new_url = get_permalink($logout->ID); } update_post_meta($item->ID, '_menu_item_url', $new_url); wp_update_post(array('ID' => $item->ID, 'post_title' => $logout->post_title)); } foreach ($pages_deleted as $page) { if ($page && $item->object_id == $page && $item->object == 'page') { wp_delete_post($item->ID); } } } } }
public function getCommunityBrandingImage($slugOfChapter) { $UI = new UI(); $chapter = get_page_by_path($slugOfChapter, OBJECT, 'chapters'); $image = $UI->getPostFeaturedImageURL(get_post_thumbnail_id($chapter->ID), 'original'); echo $image; }
/** * Display a playlist. * * @since 1.0.0 * @todo Add an arg to specify a template path that doesn't exist in the /cue directory. * * @param mixed $post A post ID, WP_Post object or post slug. * @param array $args */ function cue_playlist($post, $args = array()) { if (is_string($post) && !is_numeric($post)) { // Get a playlist by its slug. $post = get_page_by_path($post, OBJECT, 'cue_playlist'); } else { $post = get_post($post); } if (!$post || 'cue_playlist' !== get_post_type($post)) { return; } $tracks = get_cue_playlist_tracks($post); if (empty($tracks)) { return; } if (!isset($args['enqueue']) || $args['enqueue']) { Cue::enqueue_assets(); } $template_names = array("playlist-{$post->ID}.php", "playlist-{$post->post_name}.php", "playlist.php"); // Prepend custom templates. if (!empty($args['template'])) { $add_templates = array_filter((array) $args['template']); $template_names = array_merge($add_templates, $template_names); } $template_loader = new Cue_Template_Loader(); $template = $template_loader->locate_template($template_names); $classes = array('cue-playlist'); $classes[] = isset($args['show_playlist']) && false == $args['show_playlist'] ? 'is-playlist-hidden' : ''; $classes = implode(' ', array_filter($classes)); echo '<div class="cue-playlist-container">'; do_action('cue_before_playlist', $post, $tracks, $args); include $template; do_action('cue_after_playlist', $post, $tracks, $args); echo '</div>'; }
public function getBySlug($slug) { $this->post = get_page_by_path($slug, OBJECT, 'jksnippet'); if ($this->post) { $this->setupFromPost(); } }
/** * @since 3.0.0 */ function wordlift_ajax_redirect() { $url = $_GET['url']; $link = get_permalink(get_page_by_path('timeline-event')); header('Location: ' . $link . '?url=' . urlencode($url)); wp_die(); }
public function redirect() { // Keyword to check for in URL $keyword = urlencode(WPUltimateRecipe::option('print_template_keyword', 'print')); if (strlen($keyword) <= 0) { $keyword = 'print'; } // Current URL $schema = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://'; $url = $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Check if URL ends with /print preg_match("/^(.*?)\\/{$keyword}()\$/", $url, $url_data); if (empty($url_data)) { // Check if URL ends with /print/parameters preg_match("/^(.*?)\\/{$keyword}\\/(.*?)\$/", $url, $url_data); } if (isset($url_data[1])) { $post_id = url_to_postid($url_data[1]); $post = get_post($post_id); if ($post_id == 0) { // Check for plain permalinks $slug = substr(strrchr($url_data[1], '='), 1); if ($slug) { $post = get_page_by_path($slug, OBJECT, WPURP_POST_TYPE); } } if ($post && $post->post_type == WPURP_POST_TYPE) { $recipe = new WPURP_Recipe($post); $this->print_recipe($recipe, $url_data[2]); exit; } } }
function uf_gallery_output($gallerySlug = '') { $output = ''; $galleryPost = get_page_by_path($gallerySlug, OBJECT, 'uf_gallery'); //Valid Gallery if ($galleryPost) { //Raw list of IDs $galleryImagesRaw = get_post_meta($galleryPost->ID, 'uf_gallery_images', true); //How many columns we need to display in $galleryNumberOfColumns = get_post_meta($galleryPost->ID, 'uf_gallery_number_of_columns', true); //Fullsize image size used $galleryFullSize = get_post_meta($galleryPost->ID, 'uf_gallery_full_size_image_slug', true); //Thumbnail image size used $galleryThumbnailSize = get_post_meta($galleryPost->ID, 'uf_gallery_thumbnail_image_slug', true); switch ($galleryNumberOfColumns) { case 2: $columnSize = 6; break; case 3: $columnSize = 4; break; case 4: $columnSize = 3; break; case 6: $columnSize = 2; break; default: $columnSize = 3; break; } $output .= '<div class="row">'; //Loop through raw IDs and pull out correct images + caption $count = 1; foreach ($galleryImagesRaw as $image_id) { $fullsize = wp_get_attachment_image_src($image_id, $galleryFullSize); $fullsize = $fullsize[0]; $thumbnail = wp_get_attachment_image_src($image_id, $galleryThumbnailSize); $thumbnail = $thumbnail[0]; $caption = get_post($image_id); // echo $columnSize; $output .= "<div class='col-md-{$columnSize} margin-bottom'>"; $output .= "<a href='{$fullsize}' data-toggle='lightbox' data-title='{$caption->post_excerpt}' data-gallery='uf-gallery-{$gallerySlug}'>"; $output .= "<img src='{$thumbnail}' class='img-responsive margin-auto'>"; $output .= "</a>"; $output .= "</div>"; if ($count % $galleryNumberOfColumns == 0) { $output .= "</div>"; $output .= '<div class="row">'; } $count++; } $output .= '</div>'; } else { $output .= 'No gallery found'; } // $output .= 'function uf_gallery_output - uf-gallery.php line 94'; return $output; }
function page_id($slug) { $page = get_page_by_path($slug, 'OBJECT', 'page'); if ($page) { return $page->ID; } return null; }
function get_post_by_slug(WP_REST_Request $request) { $slug = $request['slug']; $return['slug'] = $slug; $return['post'] = get_page_by_path($slug, ARRAY_A, 'post'); $response = new WP_REST_Response($return); return $response; }
public static function get_page_link($slug) { $page = get_page_by_path($slug); if (!$page) { return ''; } echo get_page_link($page->ID); }
public static function get_url() { static $cache = null; if ($cache === null) { $cache = theme_cache::get_permalink(get_page_by_path(self::$page_slug)->ID); } return $cache; }
function cyb_parse_query($wp_query) { if (get_page_by_path($wp_query->query_vars['name'])) { $wp_query->is_single = false; $wp_query->is_page = true; } }