Looking for a hook for post.php

You can add your code to the init action hook and check global $pagenow variable: add_action( ‘init’, ‘wpse8170_check_from_var’ ); function wpse8170_check_from_var() { global $pagenow; if ( ‘post.php’ != $pagenow || ! isset( $_GET[‘post’] ) || ! isset( $_GET[‘from’] ) || 1 != (int) $_GET[‘from’] ) { return; } update_post_meta( (int) $_GET[‘post’], ‘EDITED’, ‘true’ ); }

Plugin init hook

There’s the plugins_loaded hook for normal Plugins and muplugins_loaded, which runs earlier. My best advice for hooks is making cross file searches for do_action or dump the content of the all hook with $GLOBALS[‘wp_filter’][ current_filter() ];.

Hook when new CPT published AND postmeta inserted

I believe you can do it using the save_post hook, than do a conditional check for the post’s post-type and the value of its post meta. add_action( ‘save_post’, ‘do_some_function’); function do_some_function($post_id) { global $post; $post_type_as_taxonomy = array(‘cpt-1′,’cpt-2′); // this is your hooked custom post types $post = get_post( $post_id ); if(in_array($post->post_type, $post_type_as_taxonomy) && $post->post_status==’publish’){ // … Read more

Strange behaviour with add_{$meta_type}_metadata | add_post_metadata filter

Ok I’ve found the solution… I have had to call add_filter outside my plugin class, because of WordPress hooks priority. With the actual code, I call add_filter after the ‘init’ event, that’s probably too late. If I move this line of code: add_filter(‘add_post_metadata’,array(&$this,’filter_negozi_add_metadata’),10,5); on top of the file, the hook works like expected. So to … Read more

Implement Hooks Using Array

What’s wrong with good old do_action? 😉 You could write a simple wrapper: function wpse81578_hook( $hook ) { do_action( $hook ); } If you’re looking for something dynamic, take a look at the do_atomic function of the Hybrid theme framework: it “adds contextual action hooks to the theme. This allows users to easily add context-based … Read more

new_to_publish fires multiple times

OK! found how to – there is 2 little information about how to attach a function to a status change but this hook does the job and does it well. function miniupdate_webnews( $new_status, $old_status, $post ) { if ( $old_status == ‘draft’ && $new_status == ‘publish’ ) { // YOUR FUNCTION HERE… } } add_action( … Read more

WordPress capabilities and restricted categories access

I think best hook should be ‘template_redirect’, when this hook is fired main query is already set, so you can look at queried object and if the user has no required capability you can redirect request somewhere: add_action( ‘template_redirect’, function() { if ( ( is_category( ‘special-category’ ) || is_singular() && has_category( ‘special-category’, get_queried_object() ) ) … Read more

Get post or page id early

For mee it seems that the template_redirect hook worked. Thanks to Pieter Goosen. Heres a solution that should work on earlier hooks: function gdymc_object_exists( $object_id ) { return ( get_the_title( $object_id ) ) ? true : false; } function gdymc_objectID() { if( is_numeric( $_GET[‘page_id’] ) ): $object_id = $_GET[‘page_id’]; elseif( is_numeric( $_GET[‘p’] ) ): $object_id … Read more

Hook for when a page template is changed

If you want to toggle the editor “on the fly”, you’ll need to revert to a pure JavaScript solution, and only ever “visually” hide it (as opposed to removing it server-side): function wpse_189693_hide_on_template_toggle() { $screen = get_current_screen(); if ( $screen && $screen->id === ‘page’ ) : ?> <script> jQuery( “#page_template” ).change( function() { jQuery( “#postdivrich” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)