/**
 * This function handles the actual redirection to the target.
 */
function cap_redirect_short_urls()
{
    global $post;
    if (is_singular('cap_short_urls')) {
        // Check for the existance of legacy url information. Lead with that if present.
        if (get_post_meta($post->ID, 'legacy_url_redirect_target', true)) {
            $legacy_url = get_post_meta($post->ID, 'legacy_url_redirect_target', true);
            // Let's get the actual domain from the legacy url...
            $parse = parse_url($legacy_url);
            $domain = $parse['host'];
            // ... if it is thinkprogress.org then proceed with idenfication of the post targeted. Otherwise just do a straight up redirect.
            if ('thinkprogress.org' === $domain || 'www.thinkprogress.org' === $domain) {
                // We could probably just get away with passing the old url in however... we want to make sure that if in the future the target posts permalink is changed then this short url will still work. So to that end we're going to use url_to_postid() to get the ID of the target post to past into get_permalink().
                $post_id = url_to_postid($legacy_url);
                $target = get_permalink($post_id);
                // This will add the ID of the short url post to the target post so that the get_shortlink function will work. It will only do so once bc it checks for unique existence.
                add_post_meta($post_id, 'post_short_url_target', '' . $post->ID . '', true);
            } else {
                $target = $legacy_url;
            }
        } elseif (get_post_meta($post->ID, 'url_redirect_target', true)) {
            $target = get_post_meta($post->ID, 'url_redirect_target', true);
        } elseif (get_post_meta($post->ID, 'post_redirect_target', true)) {
            $target = get_permalink(get_post_meta($post->ID, 'post_redirect_target', true));
        } else {
            $target = get_bloginfo('url');
        }
        wp_redirect($target);
        exit;
        echo '<!--Short URL Away-->';
    }
}
Example #2
1
 /**
  * Clear something from the cache
  *
  * @param array $args
  * @param array $vars
  */
 function flush($args = array(), $vars = array())
 {
     if (function_exists('w3tc_pgcache_flush')) {
         $args = array_unique($args);
         do {
             $cache_type = array_shift($args);
             switch ($cache_type) {
                 case 'db':
                 case 'database':
                     if (w3tc_dbcache_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'minify':
                     if (w3tc_minify_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'object':
                     if (w3tc_objectcache_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'post':
                 default:
                     if (isset($vars['post_id'])) {
                         if (is_numeric($vars['post_id'])) {
                             w3tc_pgcache_flush_post($vars['post_id']);
                         } else {
                             WP_CLI::error('This is not a valid post id.');
                         }
                         w3tc_pgcache_flush_post($vars['post_id']);
                     } elseif (isset($vars['permalink'])) {
                         $id = url_to_postid($vars['permalink']);
                         if (is_numeric($id)) {
                             w3tc_pgcache_flush_post($id);
                         } else {
                             WP_CLI::error('There is no post with this permalink.');
                         }
                     } else {
                         if (isset($flushed_page_cache) && $flushed_page_cache) {
                             break;
                         }
                         $flushed_page_cache = true;
                         w3tc_pgcache_flush();
                     }
             }
         } while (!empty($args));
     } else {
         WP_CLI::error('The W3 Total Cache could not be found, is it installed?');
     }
 }
Example #3
0
 public static function get_top_pages($range = 7, $amount = 20, $post_type = 'post')
 {
     $cache_key = $post_type . '-' . $range . '-' . $amount;
     if (false === ($posts = self::get_cache_value($cache_key, 'piwik_most_viewed'))) {
         $parameters = array('period' => 'range', 'date' => date('Y-m-d', strtotime('-' . $range . ' day')) . ',' . date('Y-m-d', strtotime('+1 day')), 'flat' => 1, 'filter_limit' => $amount + 20, 'filter_sort_order' => 'DESC', 'filter_sort_column' => 'nb_hits');
         $data = self::request('Actions.getPageUrls', $parameters);
         $posts = array();
         if (!is_wp_error($data) && !is_object($data)) {
             foreach ($data as $item) {
                 $post_id = url_to_postid($item['url']);
                 if ($post_id) {
                     $post = get_post($post_id);
                     if ($post->post_type == $post_type) {
                         $posts[] = $post_id;
                     }
                 }
                 if (count($posts) >= $amount) {
                     break;
                 }
             }
         }
         self::set_cache_value($cache_key, $posts, 'piwik_most_viewed', self::$timeout);
     }
     return $posts;
 }
 /**
  * Build object from posts
  *
  * @param String $posts of HTML to parse
  *
  * @return Mixed collection of posts
  */
 public static function build($posts)
 {
     $collection = [];
     $document = new \DOMDocument();
     $document->loadHTML($posts);
     $iterator = 0;
     $articles = $document->getElementsByTagName("li");
     foreach ($articles as $article) {
         $post = new \StdClass();
         $links = $article->getElementsByTagName("a");
         $images = $article->getElementsByTagName("img");
         $excerpts = $article->getElementsByTagName("small");
         foreach ($links as $link) {
             if (0 == $iterator % 2) {
                 $iterator++;
                 continue;
             }
             $iterator++;
             $post->link = $link->getAttributeNode('href')->value;
             $post->title = $link->textContent;
             $post->category = get_the_category(url_to_postid($post->link))[0]->name;
         }
         foreach ($images as $image) {
             $post->image = $image->getAttributeNode('src')->value;
         }
         foreach ($excerpts as $excerpt) {
             $post->excerpt = $excerpt->textContent;
         }
         $collection[] = $post;
     }
     return $collection;
 }
 function get_entries($process_comment_func = NULL)
 {
     if (function_exists('set_magic_quotes_runtime')) {
         set_magic_quotes_runtime(0);
     }
     $xml = simplexml_load_file('compress.zlib://' . $this->file);
     // simple "are we a disqus export?" check
     if (!$xml || $xml->getName() !== 'disqus') {
         return false;
     }
     foreach ($xml->thread as $thread) {
         $attributes = $thread->attributes('dsq', true);
         $threadid = (int) $attributes['id'];
         $link = (string) $thread->link;
         if (empty($this->thread_to_post_id[$threadid])) {
             if (trailingslashit($link) == trailingslashit(get_option('siteurl'))) {
                 $this->thread_to_post_id[$threadid] = (int) get_option('page_on_front');
             } else {
                 $this->thread_to_post_id[$threadid] = url_to_postid($link);
                 // echo "<li>URL to postid: <code>", $link, "</code> - <code>", $this->thread_to_post_id[$threadid], "</code></li>";
             }
         }
     }
     if ($process_comment_func) {
         foreach ($xml->post as $comment) {
             call_user_func($process_comment_func, $comment);
         }
     }
     return true;
 }
Example #6
0
 protected static function _getPostIdsByConfig($key, $type)
 {
     if (!$key) {
         $key = self::getCurrentPageKey();
     }
     $cid = $key . $type;
     if (isset(self::$idsCache[$cid])) {
         return self::$idsCache[$cid];
     }
     $option = self::getOption($key);
     if (!isset($option[$type]) || !$option[$type]) {
         return array();
     }
     $post_ids = array();
     date_default_timezone_set('America/Sao_Paulo');
     /*Realiza  busca de posts no vetor de posts destacados*/
     foreach ($option[$type] as $post) {
         /*Não exibe posts expirados*/
         if ($post['data_expiracao'] == "" || !(strtotime($post['data_expiracao']) < strtotime(date('d/m/Y H:i', time())))) {
             $url = trim($post['url']);
             $post_id = url_to_postid($url);
             if ($post_id) {
                 $post_ids[] = $post_id;
             }
         }
     }
     self::$idsCache[$cid] = $post_ids;
     return $post_ids;
 }
 function check_for_cache()
 {
     if (isset($_GET['force_skip_caching'])) {
         return;
     }
     // only for is_single()
     $postID = url_to_postid("http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
     if (is_numeric($postID) == false) {
         return;
     }
     $cacheDirectory = dirname(__FILE__) . "/files/";
     if (file_exists($cacheDirectory . "{$postID}.html") == true) {
         $postContent = file_get_contents($cacheDirectory . "{$postID}.html");
         echo $postContent;
         exit;
     } else {
         $url = get_site_url() . "?p={$postID}&force_skip_caching=true";
         try {
             $postContent = $this->doFetchUrl($url);
             $cacheFile = fopen($cacheDirectory . "{$postID}.html", "w");
             fwrite($cacheFile, $postContent);
             $this->doRedirect($cacheDirectory, $postID);
         } catch (Exception $e) {
             return;
         }
     }
 }
Example #8
0
function heib_get_post()
{
    global $heib__Response;
    if (!is_null($heib__Response) && is_a($heib__Response, 'HEIBResponse')) {
        $query = $heib__Response->query();
        $contextUrl = isset($query['contextUrl']) ? $query['contextUrl'] : '';
        $contextUrl = stripslashes($contextUrl);
        if ($contextUrl !== '') {
            if ($postId = url_to_postid($contextUrl)) {
                $post = get_post($postId);
                //setup the current post
                setup_postdata($GLOBALS['post'] =& $post);
                return $post;
            }
        } else {
            //no contextUrl is provide, return a random post a example
            $post = query_posts('orderby=rand&showposts=1');
            if ($post) {
                //setup the current post
                setup_postdata($GLOBALS['post'] =& $post[0]);
            }
            return $post ? $post[0] : null;
        }
    }
    //no post found
    return null;
}
Example #9
0
 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;
         }
     }
 }
Example #10
0
function Record_User_Event()
{
    $Path = ABSPATH . 'wp-load.php';
    include_once $Path;
    global $wpdb;
    global $ewd_feup_user_events_table_name;
    $User_ID = $_POST['User_ID'];
    $Event_Value = $_POST['Target'];
    $Event_Location = $_POST['Location'];
    $Event_Location_ID = url_to_postid($Event_Location);
    if ($Event_Location_ID != 0) {
        $Event_Location_Title = get_the_title($Event_Location_ID);
    } else {
        $Event_Location_Title = $Event_Location;
    }
    $Event_Type = Get_Event_Type($Event_Value);
    $Event_Target_ID = url_to_postid($Event_Value);
    if ($Event_Target_ID == 0) {
        $Event_Target_ID = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid=%s", $Event_Value));
    }
    if ($Event_Target_ID != 0) {
        $Event_Target_Title = get_the_title($Event_Target_ID);
    } else {
        $Event_Target_Title = $Event_Value;
    }
    Add_User_Event($User_ID, $Event_Type, $Event_Location, $Event_Location_ID, $Event_Location_Title, $Event_Value, $Event_Target_ID, $Event_Target_Title);
}
Example #11
0
 /**
  * Callback for our API endpoint.
  *
  * Returns the JSON object for the post.
  *
  * @param WP_REST_Request $request Full details about the request.
  *
  * @return WP_Error|WP_REST_Response
  */
 public function get_oembed_response(WP_REST_Request $request)
 {
     $post_id = url_to_postid($request['url']);
     /**
      * Filter the determined post id.
      *
      * @param int    $post_id The post ID.
      * @param string $url     The requestd URL.
      */
     $post_id = apply_filters('rest_oembed_request_post_id', $post_id, $request['url']);
     if (0 === $post_id) {
         return new WP_Error('rest_oembed_invalid_url', __('Invalid URL.', 'oembed-api'), array('status' => 404));
     }
     // Todo: Perhaps just default to json if something invalid is provided.
     if (!in_array($request['format'], array('json', 'xml'))) {
         return new WP_Error('rest_oembed_invalid_format', __('Invalid format.', 'oembed-api'), array('status' => 501));
     }
     /**
      * Current post object.
      *
      * @var WP_Post $post
      */
     $post = get_post($post_id);
     /**
      * User object for the post author.
      *
      * @var WP_User $author
      */
     $author = get_userdata($post->post_author);
     /**
      * Filter the allowed minimum width for the oEmbed response.
      *
      * @param int $width The minimum width. Defaults to 200.
      */
     $minwidth = apply_filters('rest_oembed_minwidth', 200);
     /**
      * Filter the allowed maximum width for the oEmbed response.
      *
      * @param int $width The maximum width. Defaults to 600.
      */
     $maxwidth = apply_filters('rest_oembed_maxwidth', 600);
     $width = $request['maxwidth'];
     if ($width < $minwidth) {
         $width = $minwidth;
     } else {
         if ($width > $maxwidth) {
             $width = $maxwidth;
         }
     }
     // Todo: this shouldn't be hardcoded.
     $height = ceil($width / 16 * 9);
     /**
      * Filters the oEmbed response data.
      *
      * @param array $data The response data.
      */
     $data = apply_filters('rest_oembed_response_data', array('version' => '1.0', 'provider_name' => get_bloginfo('name'), 'provider_url' => get_home_url(), 'author_name' => $author->display_name, 'author_url' => get_author_posts_url($author->ID, $author->user_nicename), 'title' => $post->post_title, 'type' => 'rich', 'width' => $width, 'height' => $height, 'html' => get_post_embed_html($post, $width, $height)));
     return $data;
 }
Example #12
0
 function url_to_blog_card_tag($url)
 {
     if (!$url) {
         return;
     }
     $url = strip_tags($url);
     //URL
     $id = url_to_postid($url);
     //IDを取得(URLから投稿ID変換)
     if (!$id) {
         return;
     }
     //IDを取得できない場合はループを飛ばす
     global $post;
     $post_id = get_post($id);
     setup_postdata($post_id);
     $exce = $post_id->post_excerpt;
     $title = $post_id->post_title;
     //タイトルの取得
     $date = mysql2date('Y-m-d H:i', $post_id->post_date);
     //投稿日の取得
     $excerpt = get_content_excerpt($post_id->post_content, get_excerpt_length());
     //抜粋の取得
     if (is_wordpress_excerpt() && $exce) {
         //Wordpress固有の抜粋のとき
         $excerpt = $exce;
     }
     //新しいタブで開く場合
     $target = is_blog_card_target_blank() ? ' target="_blank"' : '';
     //$hatebu_url = preg_replace('/^https?:\/\//i', '', $url);
     //はてブを表示する場合
     $hatebu_tag = is_blog_card_hatena_visible() ? '<div class="blog-card-hatebu"><a href="//b.hatena.ne.jp/entry/' . $url . '"' . $target . '><img src="//b.hatena.ne.jp/entry/image/' . $url . '" alt="はてブ数" /></a></div>' : '';
     //サイトロゴを表示する場合
     $favicon_tag = '';
     if (is_favicon_enable() && get_the_favicon_url()) {
         //ファビコンが有効か確認
         //ファビコンをイメージたいのでそのまま表示する
         //$favicon_tag = '<span class="blog-card-favicon"><img src="'.get_the_favicon_url().'" class="blog-card-favicon-img" alt="ファビコン" /></span>';
         //はてなファビコンAPIを利用する
         //$favicon_tag = '<span class="blog-card-favicon"><img src="http://favicon.st-hatena.com/?url='.site_url().'" class="blog-card-favicon-img" alt="ファビコン" /></span>';
         //GoogleファビコンAPIを利用する
         //http://www.google.com/s2/favicons?domain=nelog.jp
         $favicon_tag = '<span class="blog-card-favicon"><img src="http://www.google.com/s2/favicons?domain=' . get_this_site_domain() . '" class="blog-card-favicon-img" alt="ファビコン" /></span>';
     }
     $site_logo_tag = is_blog_card_site_logo_visible() ? '<div class="blog-card-site">' . $favicon_tag . '<a href="' . home_url() . '"' . $target . '>' . get_this_site_domain() . '</a></div>' : '';
     $date_tag = '';
     if (is_blog_card_date_visible()) {
         $date_tag = '<div class="blog-card-date">' . $date . '</div>';
     }
     //サムネイルの取得(要100×100のサムネイル設定)
     $thumbnail = get_the_post_thumbnail($id, 'thumb100', array('class' => 'blog-card-thumb-image', 'alt' => $title));
     if (!$thumbnail) {
         //サムネイルが存在しない場合
         $thumbnail = '<img src="' . get_template_directory_uri() . '/images/no-image.png" alt="' . $title . '" class="blog-card-thumb-image" />';
     }
     //取得した情報からブログカードのHTMLタグを作成
     $tag = '<div class="blog-card internal-blog-card"><div class="blog-card-thumbnail"><a href="' . $url . '" class="blog-card-thumbnail-link"' . $target . '>' . $thumbnail . '</a></div><div class="blog-card-content"><div class="blog-card-title"><a href="' . $url . '" class="blog-card-title-link"' . $target . '>' . $title . '</a></div><div class="blog-card-excerpt">' . $excerpt . '</div></div><div class="blog-card-footer">' . $site_logo_tag . $hatebu_tag . $date_tag . '</div></div>';
     return $tag;
 }
Example #13
0
function bayfront_header_style()
{
    $header_image = get_header_image();
    if (empty($header_image)) {
        return;
    }
    ?>
<style type="text/css">

<?php 
    if (is_single() && get_post_type() == 'property') {
        ?>
	<?php 
        $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
        ?>
	#container-wrap-header {
		background: none;
	}
<?php 
    } else {
        ?>
	<?php 
        // Get post id
        $url = explode('?', 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
        $ID = url_to_postid($url[0]);
        $page_template = get_post_meta(get_the_ID(), '_wp_page_template', true);
        ?>
	
	
	<?php 
        if ($page_template == 'page-templates/properties-subpage.php') {
            ?>
		<?php 
            $url = wp_get_attachment_url(get_post_thumbnail_id($post_id));
            ?>
		#container-wrap-header {
			background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0)), url(<?php 
            echo $url;
            ?>
) no-repeat center;
			background-size: cover;
		}
	<?php 
        } else {
            ?>
		#container-wrap-header {
			background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0)), url(<?php 
            header_image();
            ?>
) no-repeat center;
			background-size: cover;
		}
	<?php 
        }
    }
    ?>
</style>
<?php 
}
function op_remove_enigmapro_js()
{
    $checkIfLEPage = get_post_meta(url_to_postid("http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']), '_optimizepress_pagebuilder', true);
    if ($checkIfLEPage || $_GET['page'] == 'optimizepress-page-builder' || defined('OP_LIVEEDITOR')) {
        remove_action('wp_enqueue_scripts', 'weblizar_scripts', 10);
        remove_action('wp_footer', 'weblizar_footer_js', 10);
    }
}
 function op_allow_bbforum()
 {
     $forumPage = get_post(url_to_postid("http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
     if ($forumPage->post_type == 'forum') {
         op_update_option('blog_enabled', 'Y');
         op_update_option('installed', 'Y');
     }
 }
Example #16
0
function jr_mt_convert_url_arrays($settings)
{
    global $jr_mt_url_types;
    foreach ($jr_mt_url_types as $setting_key) {
        if (isset($settings[$setting_key]) && is_array($settings[$setting_key])) {
            foreach ($settings[$setting_key] as $url_key => $url_array) {
                $url = $url_array['url'];
                if (jr_mt_same_prefix_url(JR_MT_HOME_URL, $url)) {
                    $new_url_array['url'] = $url_array['url'];
                    $new_url_array['theme'] = $url_array['theme'];
                    $rel_url = jr_mt_relative_url($url, JR_MT_HOME_URL);
                    $new_url_array['rel'] = $rel_url;
                    /*	Create the URL Prep array for each of the current Site Aliases,
                    				including the Current Site URL
                    			*/
                    $new_url_array['prep'] = array();
                    foreach ($settings['aliases'] as $index => $alias) {
                        $new_url_array['prep'][] = jr_mt_prep_url($alias['url'] . '/' . $rel_url);
                    }
                    /*	Only for URL type Setting, not Prefix types.
                     */
                    if ('url' === $setting_key) {
                        /*	Try and figure out ID and WordPress Query Keyword for Type, if possible and relevant
                         */
                        if (0 === ($id = url_to_postid($url)) && version_compare(get_bloginfo('version'), '4', '>=')) {
                            $id = attachment_url_to_postid($url);
                        }
                        if (!empty($id)) {
                            $new_url_array['id'] = (string) $id;
                            if (NULL !== ($post = get_post($id))) {
                                switch ($post->post_type) {
                                    case 'post':
                                        $new_url_array['id_kw'] = 'p';
                                        break;
                                    case 'page':
                                        $new_url_array['id_kw'] = 'page_id';
                                        break;
                                    case 'attachment':
                                        $new_url_array['id_kw'] = 'attachment_id';
                                        break;
                                }
                            }
                        }
                    }
                    $settings[$setting_key][$url_key] = $new_url_array;
                } else {
                    /*	Error:
                    				Cannot convert, as URL is from a different Site Home URL,
                    				so have to delete this URL entry.
                    			*/
                    unset($settings[$setting_key][$url_key]);
                    jr_mt_messages('Setting deleted during Conversion to Version 6 format because Site URL has changed');
                }
            }
        }
    }
    return $settings;
}
Example #17
0
 /**
  * Find the correct login redirect permalink
  *
  * @param string $to redirect url
  *
  * @return string redirect url
  */
 public function getLoginRedirectPermalink($to)
 {
     $ID = url_to_postid($to);
     $translatedID = pll_get_post($ID);
     if ($translatedID) {
         return get_permalink($translatedID);
     }
     return $to;
 }
 public function __construct($post_id = -1)
 {
     // maybe bugs with this
     $post_id = $post_id != -1 ? $post_id : ($post_id = url_to_postid(wp_get_referer()));
     $this->buddypress_id = get_post_meta($post_id, 'buddypress_id', true);
     $forum_id = bbp_get_group_forum_ids($this->buddypress_id);
     $forum_id = !empty($forum_id) ? $forum_id[0] : null;
     $this->forumId = $forum_id;
     $this->translation = $this->_getTranslationList();
 }
Example #19
0
function _scripts()
{
    wp_register_script('jquery', get_stylesheet_directory_uri() . '/bower_components/jquery/dist/jquery.min.js');
    wp_enqueue_script('my-scripts', get_stylesheet_directory_uri() . '/build/js/scripts.min.js', array('angularjs', 'angularjs-route', 'angularjs-sanitize'));
    wp_enqueue_script('scripts', get_template_directory_uri() . '/build/js/scripts.min.js', array('jquery'), '20120206', true);
    // Load all of the styles that need to appear on all pages
    wp_enqueue_style('custom', get_template_directory_uri() . '/app/css/style.css');
    $url = explode('?', 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
    $post_id = url_to_postid($url[0]);
    $vcode = get_field('hero_yt_video_id', $post_id);
    wp_localize_script('scripts', 'vcode', $vcode);
}
/**
 * Convert a link to WP.me
 * @param string $link The link, before shortening
 * @return string      The link, after shortening through wp.me
 */
function ppp_apply_wpme($link)
{
    if (class_exists('Jetpack') && Jetpack::is_module_active('shortlinks')) {
        $id = url_to_postid($link);
        $result = wpme_get_shortlink($id);
        if (!empty($result)) {
            return $result;
        } else {
            return $link;
        }
    }
    return $link;
}
function tf_redirect_to_blog_base($template)
{
    global $wp_rewrite, $wp_query;
    if (!is_404() || $wp_rewrite->permalink_structure !== '/blog/%postname%/') {
        return $template;
    }
    $url = '/blog' . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    if (!($postID = url_to_postid($url))) {
        return $template;
    }
    $url = get_permalink($postID) . (parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY) ? '?' . parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY) : '') . (parse_url($_SERVER['REQUEST_URI'], PHP_URL_FRAGMENT) ? '#' . parse_url($_SERVER['REQUEST_URI'], PHP_URL_FRAGMENT) : '');
    wp_redirect($url, 301);
    exit;
}
function trail_story_filter_geo_mashup_load_user_editor($enabled)
{
    // Get access to the current WordPress object instance
    global $wp;
    // Get the base URL
    $current_url = home_url(add_query_arg(array(), $wp->request));
    // Add WP's redirect URL string
    $current_url = $current_url . $_SERVER['REDIRECT_URL'];
    // Retrieve the current post's ID based on its URL
    $id = url_to_postid($current_url);
    $post_thing = get_post($id);
    $enabled = has_shortcode($post_thing->post_content, 'frontend_trail_story_map') ? true : false;
    return $enabled;
}
Example #23
0
/**
 * Returns the ID for an attachment/media upload.
 */
function vpdfe_extract_id_from_wp_url($url)
{
    // The URL must be on this Wordpress site
    if (parse_url($url, PHP_URL_HOST) != parse_url(home_url(), PHP_URL_HOST)) {
        return;
    }
    // Gets the post ID for a given permalink
    // Can't handle pretty URLs for attachments (only the ?attachment_id=n)
    // so after this, fallback to fjarrett's code
    $id = url_to_postid($url);
    if ($id != 0) {
        return $id;
    }
    return vpdfe_get_attachment_id_by_url($url);
}
Example #24
0
 public function track()
 {
     if (is_admin() || $this->isBot() || !$this->isEnabled()) {
         return;
     }
     $curPostId = url_to_postid($this->©url->current());
     if ($curPostId) {
         $this->setAsVisited($curPostId);
     }
     $prevPost = url_to_postid($this->©var->_SERVER('HTTP_REFERER'));
     $from = (int) $this->©var->_GET('xrp_f');
     if ($prevPost && $prevPost == $from && !$this->©user->is_super_admin()) {
         $this->©db_actions->incrementClick($from, $curPostId);
     }
 }
 /**
  * Callback for our API endpoint.
  *
  * Returns the JSON object for the post.
  *
  * @param WP_REST_Request $request Full data about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function get_item($request)
 {
     $post_id = url_to_postid($request['url']);
     /**
      * Filter the determined post id.
      *
      * @param int    $post_id The post ID.
      * @param string $url     The requestd URL.
      */
     $post_id = apply_filters('oembed_request_post_id', $post_id, $request['url']);
     if (0 === $post_id) {
         return new WP_Error('oembed_invalid_url', __('Invalid URL.', 'oembed-api'), array('status' => 404));
     }
     return get_oembed_response_data($post_id, $request['maxwidth']);
 }
 function op_fusioncore_shortcodeJSFix()
 {
     $checkIfLEPage = get_post_meta(url_to_postid("http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']), '_optimizepress_pagebuilder', true);
     $pageBuilder = false;
     if (isset($_GET['page'])) {
         $pageBuilder = $_GET['page'] == 'optimizepress-page-builder' ? true : false;
     }
     $liveEditorAjaxInsert = false;
     if (isset($_REQUEST['action'])) {
         $liveEditorAjaxInsert = $_REQUEST['action'] == 'optimizepress-live-editor-parse' ? true : false;
     }
     if ($pageBuilder || $liveEditorAjaxInsert) {
         remove_filter('mce_external_plugins', array(FusionCore_Plugin::get_instance(), 'add_rich_plugins'), 10);
     }
 }
Example #27
0
 public function get_post_by_url()
 {
     global $gb_json_api;
     global $wpdb;
     $requested_post = $gb_json_api->query->get('url');
     $requested_post = str_replace("\\", "", $requested_post);
     $gbid = url_to_postid($requested_post);
     if ($gbid == 0) {
         $gb_json_api->error("Not found.");
     }
     $posts = $gb_json_api->introspector->get_posts(array('p' => $gbid), true);
     $post = new GB_JSON_API_Post($posts[0]);
     $response = array('post' => $post);
     return $response;
 }
Example #28
0
function ihc_init()
{
    $url = IHC_PROTOCOL . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    $current_user = false;
    if (isset($_REQUEST['ihcaction']) && $_REQUEST['ihcaction'] != '') {
        /*  ******************* REGISTER, LOGIN, LOGOUT, UPDATE, RESET PASSWORD ************************/
        ihc_init_form_action($url);
    } else {
        /*  ******************* REDIRECT or add_action to replace content **********************/
        $postid = url_to_postid($url);
        //getting post id
        if ($postid == 0) {
            $cpt_arr = ihc_get_all_post_types();
            $the_cpt = FALSE;
            $post_name = FALSE;
            foreach ($cpt_arr as $cpt) {
                if (!empty($_GET[$cpt])) {
                    $the_cpt = $cpt;
                    $post_name = $_GET[$cpt];
                    break;
                }
            }
            if ($the_cpt && $post_name) {
                $cpt_id = ihc_get_post_id_by_cpt_name($the_cpt, $post_name);
                if ($cpt_id) {
                    $postid = $cpt_id;
                }
            } else {
                //test if its homepage
                $homepage = get_option('page_on_front');
                if ($url == get_permalink($homepage)) {
                    $postid = $homepage;
                }
            }
        }
        ihc_if_register_url($url);
        //test if is register page
        ihc_block_page_content($postid, $url);
        //block page
    }
    /////////////BLOCK BY URL
    ihc_block_url($url, $current_user);
    //function available in public/functions.php
    //remove admin bar
    if (!current_user_can('administrator')) {
        show_admin_bar(false);
    }
}
 public function getWordpressController(Request $request, $e)
 {
     var_dump('test');
     return false;
     var_dump('test');
     $this->get('wordpress.loader')->load();
     $post_id = url_to_postid('index.php' . $request->getPathInfo());
     if ($post_id == null) {
         throw $e;
     } else {
         $request->attributes->set('_controller', 'GenericWordpressBundle:Default:wordpress');
         $request->attributes->set('_post_id', $post_id);
         $callback = $this->defaultResolver->getController($request);
         return $callback();
     }
 }
 public function displayPatreonCampaignBanner($patreon_level)
 {
     /* patreon banner when user patronage not high enough */
     /* TODO: get marketing collateral */
     //return '<img src="http://placehold.it/500x150?text=PATREON MARKETING COLLATERAL"/>';
     //TAO get the patreon pitch page and display it
     //TAO this is the patreon pitch page
     $TAO_patreon_pitch_page_url = get_option('tao-patreon-pitch-page', '');
     //if options comes back with something, then replace the $content
     if ($TAO_patreon_pitch_page_url) {
         //I have a full url from the options page, convert that into an DI
         $TAO_patreon_pitch_page_id = url_to_postid($TAO_patreon_pitch_page_url);
         //the id was found, get the content of that post now
         if ($TAO_patreon_pitch_page_id) {
             //Display a message for the viewer to usnderstand why they cannot see the content if the option is filled out
             $TAO_patreon_pitch_reason = get_option('tao-patreon-pitch-reason', '');
             if ($TAO_patreon_pitch_reason) {
                 //check to see if $patreon_level exists in string and replace it with $patreon_level var
                 $TAO_patreon_pitch_reason = str_replace('$patreon_level', '$' . $patreon_level, $TAO_patreon_pitch_reason);
                 //$content = '[message_box type="note" icon="yes"]' . $TAO_patreon_pitch_reason . '[/message_box][hr]';
                 $content = $TAO_patreon_pitch_reason;
             }
             //get the content from a post ID, which is the patreon pitch page
             $content .= get_post_field('post_content', $TAO_patreon_pitch_page_id);
             return $content;
         }
     }
 }