• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

wordpress

Run WP-Cron with no visitors

June 1, 2015 by Webhead

Got a website with noone visits or simply a website that is private but still need WP-Cron to be run?  no problem, you have 2 easy options.

1) Setup a free account with set https://www.setcronjob.com ( i like them better because they enable email notifications on the free account).   Create a cron job to visit wp-cron.php on your domain.

2) set up a scheduled task or cron job on your computer.  Mac OS X and Windows PC.  Problem with this though is your computer needs to be on with internet access, and if you ever buy another computer (and don’t turn your current one on) this job will never run:

https://developer.wordpress.org/plugins/cron/hooking-into-the-system-task-scheduler/

Filed Under: Coding Tagged With: wordpress

Order Non-hierarchical Custom Post Types

May 15, 2015 by Webhead

Non-hierarchical post types are like regular posts which normally do not have a menu_order attribute.  Hierarchical post type are like pages which allows a parent/child and is normally ordered by the menu_order attribute.  What if you have a custom post type that shouldn’t have a parent/child, but you still want to order it by something other than the post date?  This code does the trick on the admin side.

https://wordpress.org/support/topic/sorting-by-menu_order-in-admin-screen-on-non-hierarchical-custom-post-types

Filed Under: Coding Tagged With: php, wordpress

Easy Way to Add a Class to a Menu Item in WordPress

June 20, 2014 by Webhead

Go to Appearance -> Menus.  Open up Screen Options in the top right.  Click on the CSS Classes checkbox under Show Advanced menu properties.  Now each menu item has a textbox where you can enter css classes.

Filed Under: Coding Tagged With: wordpress

WordPress Heartbeat API

April 29, 2014 by Webhead

I could not find any extensive documentation on the WordPress Heartbeat API, so I am writing here to remember what I have learned through various tutorials throughout the web.

The Heartbeat API is written in Javascript.  Think of it like a javascript function that gets run every 60 seconds (depending on the interval) which sends data via POST to the server and then the server returns a response.  All of which you can easily hook into.  It was introduced in WordPress 3.6.

Quick Examples

PHP

// server received whatever parameters from when javascript triggered the "heartbeat-send" event.
function myplugin_heartbeat_received( $response, $data ) {
if ( !empty( $data['myplugin_id'] ) ) {
$response['myplugin_got_it'] = true;
}
return $response;
}
add_filter( 'heartbeat_received', 'myplugin_heartbeat_received', 10, 2 );

Javascript

jQuery(document).ready(function($) {
wp.heartbeat.interval= 15;
// set some parameters when it's time to send data to the server
$(document).on('heartbeat-send.myplugin', function(e, data){
data['myplugin_id'] = my_id;
});

// do something when your page gets a response.
$(document).on('heartbeat-tick.myplugin', function(e, data){

if ( data.hasOwnProperty( 'myplugin_got_it' ) ) {
refreshPage();
}
});

});

Heartbeat Pulse Interval

The ‘heartbeat_settings’ filter gets applied in the ‘init’ hook, priority 0 in wp_default_scripts in wp-includes/script-loader.php.  So if you do use the hook on the server-side and want to only run it on certain pages, be prepared to parse the URL because a lot of WP functions aren’t available at that time.  Alternatively you can set the interval in javascript with wp.heartbeat.interval(15) where 15 is seconds.  Note some other tutorials say to use ‘fast’, ‘standard’, ‘slow’, but that didn’t work for me for some reason.

 

Tutorials

I found these tutorials to be the most helpful.

http://code.tutsplus.com/tutorials/the-heartbeat-api-getting-started–wp-32446

http://code.tutsplus.com/tutorials/the-heartbeat-api-changing-the-pulse–wp-32462

http://code.tutsplus.com/tutorials/heartbeat-api-using-heartbeat-in-a-plugin–wp-32496

 

Filed Under: Coding Tagged With: javascript, php, wordpress

edit_users capability on multisite

April 29, 2014 by Webhead

No matter how hard you try, if you add the edit_user capability to a user on multi-site and that user is not a super-admin, the user will not have the edit_user capability.  This is hard-coded into WP_User’s map_meta_cap.  There is a filter so after it’s all done, you can search for it and take it out if you want.

Filed Under: Coding Tagged With: php, wordpress

WordPress is Not Remembering Me

April 28, 2014 by Webhead

Problem

All these years I’ve been checking the “Remember Me” checkbox when logging in every once in a while in hopes that WordPress will one day actually remember me.  I don’t think it ever did, but I didn’t really mind or notice much because I just thought it had something to do with my browser settings or I just didn’t come back soon enough.  Well enough is enough.  I finally had a project where I needed the Remember me functionality to work.

I made WordPress act as a web app on Apple devices by adding meta tags.  But the problem was that every time the user went to the Home screen (exited the app) they would have to log back in when re-opening the app.

Solution

Silly WordPress.  From as far back as about 5 years ago, (version 2.6.1), people have been having problems with WordPress not remembering them.  The solution is simple but is a big quirk if you ask me.  Simply drop the last slash (“/”) from the url you visit before logging in.  People have reported Remember Me working on urls like “mydomain.com/wp-admin” but not “mydomain.com/wp-admin/”.  Turns out it also works on other URLs like “mydomain.com/mypasswordprotectedpage” but  does not work on “mydomain.com/mypasswordprotectedpage/”.  Give it a try.

http://wordpress.org/support/topic/remember-me-does-not-remember-me

 

Filed Under: Coding Tagged With: wordpress

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to page 5
  • Interim pages omitted …
  • Go to page 12
  • Go to Next Page »

Primary Sidebar

Topics

apache apple block editor chrome cms css debug eCommerce embed firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery linux localization mac os x ms sql mysql open source optimize php php 5.3 responsive rest api seo svg tinymce woocommerce wordpress wpengine xss yii youtube




Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools