Are you the publisher? Claim or contact us about this channel

Embed this content in your HTML


Report adult content:

click to rate:

Account: (login)

More Channels


Channel Catalog

Channel Description:

WordPress › Support

older | 1 | .... | 385 | 386 | (Page 387) | 388 | 389 | .... | 413 | newer

    0 0

    get_current_user_id() returns 0 in external PHP page

    Sorry... I posted the original in the plugins & hacks group...

    I am writing a plugin that has an non WP page in it to record votes in a database table and return JSON of the vote counts. I have spent the last few hours googling and can't seem to figure out how to get get_current_user_id() to return anything but 0 in an external PHP file

    The offending code is:

    define('WP_USE_THEMES', false);
    require( $_SERVER['DOCUMENT_ROOT'].'/test/wp-blog-header.php' );
    do_action( 'login_init' );
    echo $user_id;

    this displays 0

    I tried it with:

    require( $_SERVER['DOCUMENT_ROOT'].'/test/wp-load.php' );
    echo $user_id;

    and get the same result – 0.

    I have a shortcode that works fine in a WP created page, but in my custom page do_shortcode( ‘[custom-shortcode]’ ); displays 0 as the $user_id.

    All other WP functions appear to be working – get_site_url works and I have access to other php files in my plugin that use $wpdb and they all work…

    My WP install is in the test/ directory under my main site – hence the '/test/' in the require statements. The PHP file in question is in the root of the plugin directory.

    There has got to be something simple I am missing – any ideas?

    Full page code – (obviously there is more output than just JSON – I'm trying to get the user issue figured out…):

      define('WP_USE_THEMES', false);
      require( $_SERVER['DOCUMENT_ROOT'].'/test/wp-blog-header.php' );  //tried this with wp-load.php too
      do_action( 'login_init' );
      $_SESSION['key'] = "jkshdfkjhdsfjkhaksdfkjsahfjkdbfbudsfbvjhbvjhbrukbuhbvjkhfbvjs";  //purposely set for testing
      $post_id = $_GET['id'];                                      //get post_id (SHOULD BE FROM QUERY STRING)
      echo "post_id:{$post_id}<br>";
      $url_session = $_GET['key'];                                 //get session key from URL
      echo "url session:{$url_session}<br>";
      $session_id = $_SESSION['key'];                              //get session id
      echo "session ID:{$session_id}<br>";
      $user_id = get_current_user_id();                            //get current logged in user
      echo "user_id:{$user_id}<br>";
      $vote = $_GET['vote'];                                       //get vote from query string
      echo "vote:{$vote}<br>";
      echo "site url:" . get_site_url() . "<br>";
      echo "referrer:". $_SERVER['HTTP_REFERER'] . "<br>";
      $error = 0;                                                  //set error count to 0
      $error = ( FALSE !== get_post_status( $post_id )                      ? $error : $error + 1 );  //check to see if post exists
      echo "error after post status check:{$error}<br>";
      $error = ( $user_id != 0                                              ? $error : $error + 1 );  //check to see if user logged in
      echo "error after userid check:{$error}<br>";
      $error = ( $url_session == $session_id                                ? $error : $error + 1 );  //check to see if session is valid
      echo "error after session check:{$error}<br>";
      $error = ( strpos("read_it,skip_it", $vote ) !== false                ? $error : $error + 1 );  //check to see if the vote is valid
      echo "error after vote type check:{$error}<br>";
      $error = ( FALSE !== strpos($_SERVER['HTTP_REFERER'], get_site_url()) ? $error : $error + 1 );  //check to url referrer
      echo "error after referrer check:{$error}<br>";
      if($error == 0){  //if all validity checks pass
        $votes = record_postvotes($user_id, $post_id, 'skip_it');   //submit the vote and get return values
        $output = "{\"votes\":[{\"ReadIt\":{$votes[0]['read_it']},\"SkipIt\":{$votes[0]['skip_it']}}]}";
      } else {
        $output = '';               //otherwise, return nothing
      } //end error check
      echo $output;

    0 0

    Success in getting CoAuthorsPlus to display multiple authors on main page, via edit to loop.php, HOWEVER, cannot get the appropriate display on the single post page, tried multiple variations on single.php and every time broke the page.

    Unsure how to edit the following single.php code to PROPERLY display both authors, any help GREATLY appreciated.

    if( have_posts() ) : while( have_posts() ): the_post() ?>
    <div class="post-title">
        <h1 class="inner-page"><?php the_title() ?></h1>
        <?php if(!profound_get_option('disable_post_meta')): ?>
        <div class="post-meta">
            printf( '<span class="meta-date-url">' . __( 'Posted on', 'profound' ) . '</span> %1$s<span class="meta-
    author-url">, ' . __('By', 'profound') . ' %2$s </span>',
            sprintf( '<span class="entry-date">%1$s</span>',
            sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
            get_author_posts_url( get_the_coauthor_meta( 'ID' ) ),
            esc_attr( sprintf( __( 'View all posts by %s', 'profound' ), get_the_author() ) ),
            )) ?>
        <?php endif ?>

    0 0

    I am working on adding some functionality on a Wordpress plugin which after a certain click needs to call on some shortcode through ajax.

    What I first attempted was to call the shortcode inside of the ajax processing in my functions.php file:

    add_action( 'wp_ajax_nopriv_showads', 'showads' );

    function showads(){

    echo do_shortcode('[myshortcode]');

    Where I would move the output of the shortcode in the response of the ajax call. This shortcode did not execute at all.

    So instead after some research in the "wp_localize_script" function inside of the plugin I would call the shortcode:

    wp_localize_script( 'script-handle', 'ajax_object',
    array('ajaxurl' => admin_url( 'admin-ajax.php' ),
    'adspace' => do_shortcode( '[myshortcode]' )
    And in the response of the ajax I would move the output of the shortcode.

    The problem I'm having at the moment is that as soon as the "wp_localize_script" function is called the output of the shortcode (it should create a google ad) is all stripped.

    I'd like to know if there is a way to not have the shortcode output stripped or advice if I'm trying to solve this whole thing the incorrect way.

    0 0

    Hi All,

    I've searched and have not found this posted. I was wondering if anyone else has implemented Schema JSON-LD code for your wordpress site using the 'Custom Script Plugin' to bypass the loop.

    I am not the best with messing with php files and as I know there are a lot of new schema plugins and new ones everyday, I guess I just like the idea of inputting the code myself.

    Anyone else do this? It all shows in Google's Schema tester so I believe it does work.

    0 0

    Hallo everybody,

    my topic is not new in this forum, but i still haven't found an answer.

    Currently a developing a small doodle like plugin. I use a shortcode to insert the frontend part in a post.
    Wordpress recognizes the shortcode itself but it doesn't render the content that is generated from the shortcode. In fact it renders nothing.

    Here the shortcode registration:

    add_action('init', '\EventEnroller\registerShortcode');
    function registerShortcode() {
    add_shortcode('EventEnroller', '\EventEnroller\eventController');

    I'am using namespaces to distinguish my functions from the rest of wordpress (normally you should prefix everything in your plugin, i know).

    In my handler function i use the output-buffering because there is a full bunch of html and php statements in the Test.php. In fact the Test.php holds the complete html and php code of the frontend part.

    // Get template and write in the buffer
    include (PLUGIN_DIR . '/templates/Test.php');
    $output = ob_get_contents();
    // render template
    return $output; `

    When i use the return statement (return $output) as the shortcode API describes the shortcode renders nothing.

    If a use a echo statement (echo $output) instead, tata, the content will get rendered perfectly on the top of the rest of the content in the post.
    This is not the intend postion of the shortcode.

    Here with the echo statement:

    // Get template and write in the buffer
    include (PLUGIN_DIR . '/templates/Test.php');
    $output = ob_get_contents();
    // render template
    echo $output;

    Why does the return statement renders nothing but the echo statement does????

    Hopefully somebody can help me.

    0 0

    I'm creating a custom theme with bootstrap that will be used by a photographer and I'm trying to integrate it with wordpress. My main page is in the one-page style and has following sections:
    - cover image with page title and description
    - about me section
    - portfolio with 6 exemplary photos and link to full gallery
    - contact form

    "About me" content can be edited in the admin panel (I created a separate "about me" page and linked up its ID with the section), portfolio photos are the feature images of the latest posts.
    Navbar consists of sections titles as well as link to gallery.

    And here are my questions and problems that I need to solve:

    1) How can I add a functionality to edit the cover image from the admin panel?

    2) What is the best way to create a separate gallery?
    I thought about categorizing the posts with "gallery" and "portfolio" when all of the first ones would be posted in gallery, but also some of them would be featured on the home page in portfolio section.
    Is it a good way to do that? How can it be achieved in code? Here is how the portfolio code looks like at the moment:

    <div class="row">
                        $i = 1;
                        if ( have_posts() ) : while ( have_posts() ) : the_post();
                        <div class="col-sm-4 portfolio-item">
                            <a href="#portfolioModal<?php echo $i; ?>" class="portfolio-link" data-toggle="modal">
                                <div class="caption">
                                    <div class="caption-content">
                                        <i class="fa fa-search-plus fa-3x"></i>
                                    the_post_thumbnail( 'full', array('class' => 'img-responsive') );
                        <?php $i++; ?>
                    <?php endwhile; endif; ?>

    It publishes all of the featured photos of the posts in the portfolio section.

    3) What is the best way to create a separate gallery in my case?
    Should I create the "gallery.php" file with all of the code and link it up in navbar? What should be the link destination in navbar that would lead to the gallery?

    0 0

    I have changed the post thumbnail meta box for custom type plc_person so it is: called 'Mug Shot', displays with a description and is in the main content area. It all displays correctly initially, but once an image has been selected, the description disappears. Can anyone help please? Thanks!

    add_action('do_meta_boxes', 'change_featured_image_box');
    function change_featured_image_box() {
    	remove_meta_box( 'postimagediv', 'plc_person', 'side' );
    	add_meta_box('postimagediv', __('Mug Shot'), 'change_post_thumbnail_meta_box', 'customposttype', 'normal', 'high');
    function change_post_thumbnail_meta_box( $post ) {?>
        	<label for="postimagediv"><?php _e( "This needs to be a head shot of this person stood in front of the wall in the hall. Crop to 300px x 300px with half a brick above and below their head." ); ?></label>
    	$thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
    	echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID );


    0 0

    I am working on a button which allows you to add images to a post.
    I did so using the following code which open a frame of the media library.

    frame ={
        title: 'Select or Upload',
        button: {
            text: 'Use this media'
        multiple: false,
        frame: frame_type

    My problem is that I want the frame to only show specific media types e.g. only images or only videos.
    Is there a way to achieve that behaviour?

    0 0

    Hi, I am trying to add cookies to my pop-up forms at but am having trouble getting it to work. I am very new to javascript, so I'm not sure if I'm doing this right or if I'm even close.

    The website has several downloads that the client would like to collect contact information on, so every download has a pop-up form that requires the viewer to complete in order to receive the download. To improve the user experience, the client would like for the contact form to remember the viewer's information so that they only have to enter it once.

    After some online research, I've applied the following code to my pop-up. Anyone have any ideas what I'm doing wrong here?

    This particular pop-up can be found by clicking on the Rota Brochure on this page:

    '<h1>DOWNLOAD ACCESS</h1>
    Please complete the form below to access the ROTA Brochure:

    <form action="" method="POST">
    <script type="text/javascript">var submitted=false;</script>
    <iframe name="hidden_iframe" id="hidden_iframe" style="display:none;"
    onload="if(submitted) {window.location='';}"></iframe>
    <form action="" method="post" target="hidden_iframe"

    [contact-form to='myemail' subject='PharmaSystems Downloads - New Contact']
    [contact-field label='First Name' type='name' name="usernameF" id="usernameF" required='1'/]
     [contact-field label='Last Name' type='text' name="usernameL" id="usernameL" required='1'/]
     [contact-field label='Company' type='text' name="company" id="company" required='1'/]
     [contact-field label='State / Province / Region' type='text' name="location" id="location" required='1'/]
     [contact-field label='Country' type='text' name="country" id="country" required='1'/]
     [contact-field label='Inquiry Status' type='select' required='1' options='Active Project,Just Browsing'/]
     [contact-field label='Email' type='email' name="email" id="email" required='1'/]
     [contact-field label='Phone' type='text' name="phone" id="phone" required='1'/][/contact-form]

    <function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires="+d.toUTCString();
    document.cookie = firstname + "=" + value + "; " + expires;
    document.cookie = lastname + "=" + value + "; " + expires;
    document.cookie = company + "=" + value + "; " + expires;
    document.cookie = location + "=" + value + "; " + expires;
    document.cookie = country + "=" + value + "; " + expires;
    document.cookie = email + "=" + value + "; " + expires;
    document.cookie = phone + "=" + value + "; " + expires;

    function getCookie(cname) {
    var name = firstname + "=";
    var name = lastname + "=";
    var name = company + "=";
    var name = location + "=";
    var name = country + "=";
    var name = email + "=";
    var name = phone + "=";
    var ca = document.cookie.split(';');
    for(var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
    c = c.substring(1);
    if (c.indexOf(name) == 0) {
    return c.substring(name.length, c.length);
    return "";

    function checkCookie() {
    var user = getCookie("firstname");
    var user = getCookie("lastname");
    var user = getCookie("company");
    var user = getCookie("location");
    var user = getCookie("country");
    var user = getCookie("email");
    var user = getCookie("phone");
    if (user != "") {
    alert("Welcome again " + user);
    } else {
    user = prompt("Please enter your name:", "");
    if (user != "" && user != null) {
    setCookie("username", user, 365);


    0 0

    Hi, I'm developing a plugin for work and I'm basically learning how to develop plugins for the first time. I have a question about using javascript hardcoded in the main php file for the plugin and linking to the external javascript files.

    Basically I can use document.write() if I hard code it into the plugin but, if I try to use wp_enqueue_script the javascript works but, document.write doesn't seem to work.

    So this works

    echo '<h1>Clean Post Search Settings</h1></p>
    <p>		<h2>Add/Edit Topics</h2>';?><br />
    		<script><br />;<br />
    		document.write("<h1>Main title</h1>");<br />
    		document.close();<br />

    But, document.write doesn't work here


    <p>function cps_zt_settings_page(){<br />
    	echo '<h1>Clean Post Search Settings</h1></p>
    <p>		<h2>Add/Edit Topics</h2>';<br />
    		wp_enqueue_script(cps_zt_js);<br />
    }<br />

    External Javascript file

    <br />;<br />
    document.write("<h1>Hello World</h1>");<br />
    document.close();<br />

    0 0

    How would I edit this to order the posts by the latest comment, or order by comment date.

    function order_home_asc($query) {
      if ($query->is_home() && $query->is_main_query()) {
        $query->set('orderby', 'modified');
    'orderby' => 'comment_count', 'order'=>'DESC'
    	$query->set('order', 'DESC');
    	$query->set('post_status', 'future,publish');
    add_action('pre_get_posts', 'order_home_asc');


    0 0


    Does anyone know if it is possible to restrict usernames to numbers only?

    Also, is it possible to restrict the number length to, say, 10? No more and no less.

    I am in the early stages of putting together a business case for a client who requires only numbers to be used as a username. This number is a unique identifier to their staff in their organisation, for example: 2398253635.

    Any help and guidance very much appreciated.


    0 0

    I used the following line of code in a function so I can display the child pages as links and it works great however the links are being returned in the order that the pages were created and not like the menu, I must have missed something somewhere. If I change the order numbers that will work but who wants to do that. I structured the menu so they are alphabetical but iot may not stay that way. I just want my function to follow the menu.

    '$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );'

    0 0

    Hello WP forum, I hope someone here can help me.

    I am using WordPress 4.4.1 and a twenty fifteen child theme.
    In fuctions.php I have added the following code so that every time there is an asterisk (*) it is automatically surrounded by span tags sop that I can center align it in the css targeting the .auto-style class.

    add_filter( 'the_content', 'auto_word_style' );
    function auto_word_style( $text ) {
    $text = str_replace( '*', '<span class="auto-style">* * *</span>', $text );
    return $text;

    But I need to run the code above only for a specific page template (my-template.php), so I changed the code into the following, but it doesn't work.

    if ( page_template ( "my-template.php") ) {
    	add_filter( 'the_content', 'auto_word_style' );
    	function auto_word_style( $text ) {
    	$text = str_replace( '*', '<span class="auto-style">* * *</span>', $text );
    	return $text;

    Thanks in advance,

    0 0

    Hello there! I am developing a website and my client wants that a hard coded string should be added to every post title if visitor is not logged in. how can I do this. I have used concatenation way to approach it but, seems like not working. Here is some code that i have done in the_title function in post-template.php
    if (!is_user_logged_in()) {
    $title .= "$title (string goes here...)";
    return $title;
    return $title;


    0 0
  • 05/26/16--04:33: myt007 on "embed"
  • I want to add a buton with name embed, and when press him i want to show de ifrmae code of my video from my site.....for membres who wants to put the video on their site.

    like youtube embed

    0 0


    I'm using the "Popularity Contest" plugin to show the most viewed categories. When i use it as a widget in sidebar, it works fine. But what i need is to use it in the content of the page.

    The plugin is not supported anymore, but it works fine as a widget, and i wonder what function should i call to get the proper output.

    Any ideas please?

    0 0

    Hi there, I need to customize which dashboard widgets are shown to each user. I can't do this based on user roles, I need to do it on a per specific user basis. E.g. user A can only see widget A. User B can only see widget B.

    I can't find any documentation on how to do this. Is it possible? I know it's possible to do this customization on a per-user-role basis because many plugins do that. But how about on a per-user basis?

    Both code or a plugin would be super helpful.


    0 0

    The outstanding coder Amit Agarwal has a hack regarding embedding Youtube videos which requires I insert the following into my CSS:

    <textarea> <style>
    .youtube-container { display: block; margin: 20px auto; width: 100%; max-width: 600px; }
    .youtube-player { display: block; width: 100%; /* assuming that the video has a 16:9 ratio */ padding-bottom: 56.25%; overflow: hidden; position: relative; width: 100%; height: 100%; cursor: hand; cursor: pointer; display: block; } { bottom: 0; display: block; left: 0; margin: auto; max-width: 100%; width: 100%; position: absolute; right: 0; top: 0; height: auto } { height: 72px; width: 72px; left: 50%; top: 50%; margin-left: -36px; margin-top: -36px; position: absolute; background: url("") no-repeat; }
    #youtube-iframe { width: 100%; height: 100%; position: absolute; top: 0; left: 0; }

    Here's my question (I'm a newbie): do I need to change <style> to
    something like style {

    In other words, will inserting html code such as <style> crash my CSS?

    0 0

    Hi there,

    I received a mail from Google, saying one of my sites were hacked. They detected hacked content on my website. I spent about 4 hours figuring out how this was possible. Searched the whole database, scanned all folders and also ran an Antivirus and malicious code scanner. None of the scans found any hacked content.

    Then I started looking at the php code of my WordPres theme. The code was referencing the most sold woocommerce product and was displaying it in the footer of the website. Please see in attached screenshot "WahooFitness_Image1". In the screenshot you can see that the 'Add to Cart" button links to a spam link. When looking at the code, there is no spam. Please see a screenshot of the code as attached in WahooFitness-Image2.

    The problem here was with the theme as you can see. It sets the value of the "Add to Cart" button to %s. So the source of the link that you're on. So if you did a simple WordPress search, you would change the link of the button to a spam link and Google's bot would think it was spam. Please see WahooFitness_Image3 for the source view on the page. By going to "" which simply does a WordPress search, the link of the button gets set to "" making Google's bot think your site has spam on it.

    The way they manage to get Google's bot to crawl your site is to post this link on other websites. Please see a screen shot of my WebMaster Tools "Links to your site". So Google's bot just had to crawl 1 link from those SPAM sites, and whale, my site gets marked as SPAM because there is a legit SPAM link on it.

    All this came from a vulnerability in the "WooPress - Responsive Ecommerce WordPress Theme" where they did bad coding and caused me site to be marked as SPAM. Would love to hear what the community has to say about this and I really do hope Google.

    Please find the above attached images at this link:


older | 1 | .... | 385 | 386 | (Page 387) | 388 | 389 | .... | 413 | newer