Forum Replies Created

Viewing 15 replies - 1 through 15 (of 67 total)
  • What I mean, is why did they choose to get the first message though? They could have just as easily decided to return the last message.

    Was it just something that was done without much thought, and then has been kept that way for compatibility reasons? Or is there some good reason that you’d more likely want the first message rather than the last one?

    PS I’m the OP, I must have signed in with one of my other a/cs by accident.

    • This reply was modified 7 years, 7 months ago by djeyewater. Reason: clearing up that I'm the OP
    Thread Starter djeyewater

    (@djeyewater)

    Sorry, I can’t really remember. I think that probably it did work, but the settings API way of doing thing things is so convoluted I gave up on it.

    I have seen this in a twenty twelve child theme I have as well, though I haven’t had time to debug it yet. It’s not a major issue for me.

    Thread Starter djeyewater

    (@djeyewater)

    Updated to the full version, purged the cache, and all icons showing up nicely now. Thanks for the help.

    Thread Starter djeyewater

    (@djeyewater)

    There’s been a few suggestions for wordpress plugin dependencies before, but unfortunately it is not going to be implemented. I agree it would be nice to have.

    I did think about implementing an auto-download, install and activate of your plugin when my plugin is activated, but thought it better that the user actively installs the plugin. Otherwise they might wonder where the Geo IP detection plugin had come from and disable it, not realising that it was installed by my plugin.

    The best solution would be to stop during the activation sequence (of my plugin) and output a message that your plugin will be installed as part of the process, and click OK to continue. That way the user has to acknowledge the installation of the dependency plugin. However, I don’t think this is possible as plugins aren’t allowed to output text during the activation process.

    Thread Starter djeyewater

    (@djeyewater)

    The error messages are only strict standards messages, the plugin should still work fine. If you’re seeing the error messages on your live website, then the issue is with your PHP configuration.

    Try adding ini_set('display_errors', 0); to your wp-config.php file. (Or better yet, turn off display_errors in your php.ini). It won’t fix the errors, but it will hide them.

    djeyewater

    (@djeyewater)

    1 & 2 both look like a content encoding issue, in your Chrome screenshot you can see it says “ERR_CONTENT_DECODING_FAILED”. My guess would be that somewhere the content is being zipped, but then served as unzipped (or maybe the other way round). I can’t really advise on how to fix it, but if there are some settings to do with serving compressed / zipped pages somewhere, you could play with them to see if they make any difference.

    3 A good question. It would depend on how the post views stats are generated. I did a quick search, but couldn’t see that WP has this feature, other than through plugins. If the views are generated through hits on the page as processed by wordpress, then the views would be much less with super cache enabled, as supercache ‘intercepts’ the page request before it hits wordpress.

    You could use a server log analyser (such as awstats), or javascript based stats (such as Google analytics) for more accurate stats.

    Thread Starter djeyewater

    (@djeyewater)

    Just to correct my previous post, it seems that you can’t actually use $_REQUEST. I just tried doing a quick edit and ‘content’ (and ‘post_content’) were set on $_POST, but not on $_REQUEST. So you need to check $_POST, $_GET, and $post_data. You can’t just check $_REQUEST and $post_data as I suggested previously.

    This also indicates that maybe the Codex was correct about quick edit using GET. I didn’t examine the HTTP headers, I had just assumed it was using POST since all the POST fields were filled out. But they may have been filled out by the wordpress backend rather than being filled out as part of the request.

    Thread Starter djeyewater

    (@djeyewater)

    Thanks very much for the answer!

    Thread Starter djeyewater

    (@djeyewater)

    Thanks for the info. I’ve now had a look at the core files to see how $post_data is structured.

    In wp-includes/class-wp-xmlrpc-server.php we find:
    $content .= wp_unslash($post_data['post_content']);
    and

    if ( isset( $post_data['content'] ) )
    $post_data['post_content'] = $post_data['content'];

    When I examined $_POST and $_REQUEST (when saving a post in the normal way), $_POST contains keys (and values) for ‘post_content’ and ‘content’. $_REQUEST had a key for ‘content’, but not for ‘post_content’.

    So it seems the safest way to get the post content from a function hooked into the ‘save_post’ action is probably:
    $post_content = wp_unslash(!empty($_REQUEST['content']) ? $_REQUEST['content'] : $post_data['content']);

    Thread Starter djeyewater

    (@djeyewater)

    Hi Paal

    I’ve found there is already a good tutorial on adding another sidebar to your theme: https://www.tastyplacement.com/add-sidebar-wordpress

    But to go through it quickly, in your functions.php you register your new sidebar.

    register_sidebar(array(
    	'name'          => __( 'Sidebar two', 'twentytwelve' ),
    	'id'            => 'sidebarTwo',
    	'description'   => 'Sidebar No. 2',
            'class'         => '',
    	'before_widget' => '<li id="%1$s" class="widget %2$s">',
    	'after_widget'  => '</li>',
    	'before_title'  => '<h2 class="widgettitle">',
    	'after_title'   => '</h2>' ));

    In your theme folder create a new file that will contain the code for your new sidebar. It should be named sidebar-whatever.php. In this file you need to call the sidebar you registered, ‘Sidebar two’ in my example. And if you are adding a menu placement in this sidebar, you need to set the menu location using wp_nav_menu. So, my file ‘sidebar-2.php’ contains:

    <div id="sidebar2Container" class="widget-area" role="complementary">
       <ul>
          <?php dynamic_sidebar('Sidebar two');?>
          <?php wp_nav_menu( array( 'theme_location' => 'sidebar two' ) );?>
       </ul>
    </div>

    At the moment we have placed where our custom menu will show up, but we haven’t actually made that placement available to choose in the admin area. To do, in your Functions.php file add:

    register_nav_menu( 'sidebar two', 'Sidebar 2' );

    Now when you create a menu in the admin area, you should see ‘Sidebar 2’ listed under the theme locations where the menu can appear.

    Finally, we need to make it so that our sidebar will actually appear. To do this, edit the page template(s) that you want to include the new sidebar. For this example, I’m going to add the new sidebar only to single pages, so I’m just going to edit single.php.

    At the bottom of single.php I added the call to my new sidebar. The last 3 lines of my single.php look like this:

    <?php get_sidebar(); //get the default sidebar ?>
    <?php get_sidebar('2'); //get our sidebar 2 (sidebar-2.php) ?>
    <?php get_footer(); ?>

    As you can see, my sidebar will be included straight after the primary sidebar. You can, of course, place the call to the sidebar before the content, or wherever you want. Note that I call get_sidebar('2') as my sidebar file is named sidebar-2.php. If my sidebar file was named sidebar-my-super-sidebar.php, then I would need to call get_sidebar('my-super-sidebar') to have it included.

    And that’s it really. For my own purposes that I originally asked this question about, I did something quite different. There are often multiple different ways to get the same thing done. But I believe the above process should probably suit most people wanting to add a second sidebar with a menu location.

    Hopefully someone will correct me if any of the above is wrong. (It works for me but there could be some possible conflict or best practice way of doing things that I have missed).

    Dave

    Thread Starter djeyewater

    (@djeyewater)

    Hi Paal

    I can’t remember the exact details now, but I’ll look into it and do a short tutorial like you requested. I’ll post back here when it’s done.

    Dave

    Thread Starter djeyewater

    (@djeyewater)

    I’m not planning to use the add/remove bit as it is messy, I’m planning to use the workaround given in my original post:

    add_filter('the_content', 'myTest');
     function myTest($content){
    	global $post;
    	$summary=$post->post_excerpt ? $post->post_excerpt : wp_trim_words($content,55);
    	return $content.'<p>Content edited</p>';
     }

    Thread Starter djeyewater

    (@djeyewater)

    bcworkz, thanks for the suggestion. I just tried a priority of 99 and the shortcodes were parsed correctly. I think for practical reasons I’ll stick with my wp_trim_words workaround if there aren’t any issues with it. (Having to remove the filter/action before calling get_the_excerpt and then adding it again after to prevent recursion is a bit messy). But at least now I know the answer.

    Thanks for your suggestions too mindctrl. I didn’t know that add_action was just a shortcut to add_filter.

    Cheers

    Dave

    Thread Starter djeyewater

    (@djeyewater)

    The use case is for a sharing link at the end of the article. The excerpt needs to be used (url encoded) as part of a URL. Then when you click on that link, the page will open up with the share text pre-filled with the excerpt and link.

    Unfortunately your example using $post->post_excerpt won’t always work as it relies on the post excerpt meta being filled out (which isn’t always the case). get_the_excerpt returns $post->post_excerpt if it exists, or otherwise it trims the_content down.

    I believe the solution I gave in my original question
    $summary=$post->post_excerpt ? $post->post_excerpt : wp_trim_words($content,55); is probably pretty similar to what get_the_excerpt does, though I haven’t actually looked at the code for get_the_excerpt.

    What I’d like to know is:

    1. Why do shortcodes stop working when get_the_excerpt is called from an action or filter on the_content
    2. Is my workaround okay, or is it not taking account of something that could cause issues

    Cheers

    Dave

Viewing 15 replies - 1 through 15 (of 67 total)