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


Embed this content in your HTML

Search

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' );
    
    $user_id=get_current_user_id();
    echo $user_id;

    this displays 0

    I tried it with:

    require( $_SERVER['DOCUMENT_ROOT'].'/test/wp-load.php' );
    $user_id=get_current_user_id();
    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…):

    <?php
    /*
      vote.php
    */
    
      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">
        <?php
            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>',
            get_the_date()
            ),
            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() ) ),
            get_the_author()
            )) ?>
        </div>
        <?php endif ?>
    </div>

    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]');

    wp_die();
    }
    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.

    https://wordpress.org/plugins/custom-script-integration/


    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
    ob_start();
    include (PLUGIN_DIR . '/templates/Test.php');
    $output = ob_get_contents();
    ob_end_clean();
    // 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
    ob_start();
    include (PLUGIN_DIR . '/templates/Test.php');
    $output = ob_get_contents();
    ob_end_clean();
    // render template
    echo $output;

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

    Hopefully somebody can help me.
    Thanks


    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">
    
                    <?php
    
                        $i = 1;
    
                        query_posts('showposts=6');
                        query_posts("catname=portfolio");
    
                        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>
                                    </div>
                                </div>
    
                                <?php
    
                                    the_post_thumbnail( 'full', array('class' => 'img-responsive') );
    
                                ?>
                            </a>
                        </div>
    
                        <?php $i++; ?>
    
                    <?php endwhile; endif; ?>
    
    </div>

    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 ) {?>
    	<p>
        	<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>
    	</p><?php
    	$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 = wp.media({
        title: 'Select or Upload',
        button: {
            text: 'Use this media'
        },
        multiple: false,
        frame: frame_type
    });
    frame.open();

    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 http://www.pharmasystemsusa.com 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: http://pharmasystemsusa.com/pharma-equipment/select-by-machine-type/fill-finish-lines/rota-rotary-washers/

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

    <form action="http://pharmasystemsusa.com/wp-content/uploads/2016/05/Rota-Brochure.pdf" 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='http://pharmasystemsusa.com/wp-content/uploads/2016/05/Rota-Brochure.pdf';}"></iframe>
    <form action="http://pharmasystemsusa.com/wp-content/uploads/2016/05/Rota-Brochure.pdf" method="post" target="hidden_iframe"
    onsubmit="submitted=true;">

    [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 />
    		document.open();<br />
    		document.write("<h1>Main title</h1>");<br />
    		document.close();<br />
    		</script></p>
    <p>

    But, document.write doesn't work here

    PHP

    </p>
    <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 />
    document.open();<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');

    Thanks,Pete


    0 0

    Hello,

    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.

    Paul.


    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,
    Beppe


    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;
    }
    else
    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

    Hi

    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.

    Thanks!


    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; }
    img.youtube-thumb { bottom: 0; display: block; left: 0; margin: auto; max-width: 100%; width: 100%; position: absolute; right: 0; top: 0; height: auto }
    div.play-button { height: 72px; width: 72px; left: 50%; top: 50%; margin-left: -36px; margin-top: -36px; position: absolute; background: url("http://i.imgur.com/TxzC70f.png") no-repeat; }
    #youtube-iframe { width: 100%; height: 100%; position: absolute; top: 0; left: 0; }
    </style></textarea>

    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 "www.wahoofitness.co.za/?search=YES-XXX&id=?c=803" which simply does a WordPress search, the link of the button gets set to "www.wahoofitness.co.za/?search=YES-XXX&id=?c=803" 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: https://drive.google.com/folderview?id=0By9nps1mp7AIa2swX3owUHBwd00&usp=sharing

    Regards
    Chris


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