Luke
Forum Replies Created
-
Great! Nice to know it helped someone.
Forum: Plugins
In reply to: [Perfect Images] Special characters in alt text break Picturefill methodNice one, mate!
I can put those alt attributes back in my theme/plugin. Cheers!
Should add… Bitly uses a lot of code and methods that I don’t understand. If someone could point me to the exact spot where Bitly switches out the current shortlink and replaces it with the generated Bitly shortlink, that would be great!
Forum: Hacks
In reply to: WordPress default screen optionsAdd one of the following hooks with the function (before or after, doesn’t matter).
add_action( 'add_meta_boxes_post', 'set_user_metaboxes', 10, 1 );
This runs when the post edit screen is loading.
add_action( 'user_register', 'set_user_metaboxes', 10, 1 );
This runs when a new user is created.
The second might be better. Your code (which I am also using) only changes a users settings (show/hide and order) if the user hasn’t already altered them from the new user defaults. Running this action every time a user opens a post edit page is pointless.
If you want to force the defaults on every page load, the code needs altering.
Forum: Hacks
In reply to: “publish_post” action hook shouldn’t be depreciated! Why is it?I’ve updated the Codex in all the relevant places with current and correct information about all the post status transition hooks. Hopefully, if I have understood the code thoroughly enough, the Codex should be complete and correct.
Forum: Hacks
In reply to: “publish_post” action hook shouldn’t be depreciated! Why is it?Resolved.
Forum: Hacks
In reply to: Check my wp_mail() code? For a lite edit flow notifications plugin. (Github)I’ve figured it all out.
More detail on how to make
publish_post
work is in this thread:
https://www.ads-software.com/support/topic/“publish_post”-action-hook-shouldn’t-be-depreciated-why-is-itNote:
publish_post
IS NOT DEPRECIATED, despite the Codex saying so in two places. However, it has to be handled a little differently since Version 2.3.My full plugin code is still on Github:
https://github.com/lukejanicke/roots-edit-flow/blob/master/roots-edit-flow.phpForum: Hacks
In reply to: “publish_post” action hook shouldn’t be depreciated! Why is it?Yes. It works.
The trick, apparently, seems to be putting
'2'
into the arguments ofadd_action
.My full plugin code is on Github:
https://github.com/lukejanicke/roots-edit-flow/blob/master/roots-edit-flow.phpForum: Hacks
In reply to: “publish_post” action hook shouldn’t be depreciated! Why is it?I may have found answers but am yet to test them in my plugin.
Firstly, on the add_action page is the following note.
Notes
To find out the number and name of arguments for an action, simply search the code base for the matching do_action() call. For example, if you are hooking into ‘save_post’, you would find it in post.php:
<?php do_action( 'save_post', $post_ID, $post, $update ); ?>
Your add_action call would look like:
<?php add_action( 'save_post', 'my_save_post', 10, 3 ); ?>
And your function would be:
function my_save_post( $post_ID, $post, $update ) { // Do stuff here. }
I looked in wp_includes/post.php and found this…
/** * Fires when a post is transitioned from one status to another. * * The dynamic portions of the hook name, $new_status and $post->post_type, * refer to the new post status and post type, respectively. * * @since 2.3.0 * * @param int $post_id Post ID. * @param WP_Post $post Post object. */ do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
My plugin function and action call will now look like this…
function my_function( $ID, $post ) { // Do stuff here. } add_action( 'publish_post', 'my_function', 10, 2 );
Will post results success or otherwise.
Forum: Hacks
In reply to: “publish_post” action hook shouldn’t be depreciated! Why is it?And perhaps the real crux of my question is what gets passed to these action hooks? Does
$post
get passed to all of them? Or just the post ID?Forum: Hacks
In reply to: How to customize "Insert Media" output?No worries, bcworkz. I’m also working on this on the side. I kinda get what you’re saying and I’m sure when I properly sit down to figure out how to write that JS function that I’ll be able to figure it out.
Forum: Hacks
In reply to: How to customize "Insert Media" output?I’ve had a look at media-editor.js. I tried to strip down to the insert function and then rewrite the last
html = ...
line to return just[image id="..."]
, then use admin_enqueue_script to bring it in. Doesn’t work.This JS is beyond me.
Any “for dummies” pointers on how write a JS script to override that core JS behavior?
Forum: Hacks
In reply to: My plugin with 'the_content' filter breaks trying to add excerptSolved.
if ( has_excerpt() ) { $excerpt = get_the_excerpt(); $content = sprintf( '<p class="excerpt">%s</p>%s', $excerpt, $content ); }
If there’s no excerpt, the
get_the_excerpt
filter will try to make one fromthe_content
, thus creating an infinite loop. I just had to use thehas_excerpt()
check.Forum: Hacks
In reply to: My plugin with 'the_content' filter breaks trying to add excerptIt works if there IS an excerpt. Perfectly.
If there is no excerpt, the page tries to load but comes up blank. What’s broken?
Not that you need to go look at it… but I’ve stripped down your plugin to the barest of functions needed to achieve all the renaming (of filenames and links) automatically with no admin pages and options.
https://github.com/lukejanicke/automatic-media-file-renamer/
It all seems to work (sans the infamous GUID/File name issue).
In my particular use case, full and forced renaming according to media title makes the most sense. A simple, light, behind-the-scenes plugin that does this automatically is a gem. Hope you don’t mind my hacking your work apart like that. I left full plugin attribution to you, same licenses, same notes about the original plugin and dual licenses.