Remove “Get Shortlink” button in admin of custom post type

If you filter pre_get_shortlink and return anything but false WordPress will not create a shortlink with its own logic. If your return value is empty, the shortlink UI will not be printed. Combining both leads us to: add_filter( ‘pre_get_shortlink’, ‘__return_empty_string’ ); If you want to restrict the filter to a specific post type, check the … Read more

WordPress Plugin Boilerplate – add_action hook in static “activate” function

The problem is the initialization in WordPress via register_activation_hook( __FILE__, ‘activate_IWCollege_Courses’ ); The function was fired on the Activation of a plugin, not more. You must switch to the hook init. For Custom Post types, the init hook is recommended in the codex. Custom post types must be registered during every WordPress initialization. But the … Read more

Using pre_get_posts to Filter Posts

You’re creating a new query, not altering the existing one. The pre_get_posts codex page has a note explaining that the $query argument is passed by reference and you should alter it directly. There’s no need to declare globals or return values. Update your function to be: add_action( ‘pre_get_posts’, ‘only_current’ ); function only_current( $query ) { … Read more

When should I call add_settings_section and add_settings_field?

You can call add_settings_section and add_settings_field any time before you do_settings_sections: add_action( ‘my_plugin_add_settings_sections’, function() { wp_remote_get( … ); add_settings_section( … ); add_settings_field( … ); }); // On the plugin settings page output do_action( ‘my_plugin_add_settings_sections’ ); do_settings_sections( … ); You’ll still want to register_setting() earlier though because that custom hook won’t be fired when your settings … Read more

add_action for lost_password or modify wp-login.php?action=lostpassword

got a working solution, but wordpress first validate the username or email address then my validation takes place.. I have used allow_password_reset filter instead of lostpassword_post action: add_filter( ‘allow_password_reset’, ‘my_password_reset_helper’ ); function my_password_reset_helper($true) { if (isset($_POST[‘g-recaptcha-response’])) { $array = array(‘response’ => $_POST[‘g-recaptcha-response’], ‘userip’ => $_SERVER[‘REMOTE_ADDR’], ‘secret’ => ‘asddfer345gfdg4veg45y34635345’); $result = gcaptcha($array); if (!$result) { return … Read more

Automatically Add Specified Value to Attachment Metadata upon Upload

You’re close! Try using these hooks instead. // Add post meta to new audio uploads. function auto_update_audio_meta( $post_ID ) { if ( wp_attachment_is( ‘audio’, $post_ID ) ) { add_post_meta( $post_ID, ‘artist’, ‘test’ ); } } add_action( ‘add_attachment’, ‘auto_update_audio_meta’ ); For attachment updates // Update post meta to updated audio uploads. function auto_update_audio_meta( $post_ID, $post_after, $post_before … Read more

Action on post publish

If your aim is to trigger code when a post is published, as in, the post_status of the post is set to publish, then you can hook into save_post like this: function cc_publish_wpse_263985( $postid ) { // check if post status is ‘publish’ if ( get_post_status( $postid ) == ‘publish’) ) { // do something … Read more