echo or print_r in an admin function

After the save_post hook is executed, the page is redirected, so you’re not able to see the print_r output. A simple method, if you can afford it, is to do a wp_die() just after the print_r or var_dump. Or you can check other debugging methods, like FirePHP.

How to Removing fields from the Media Uploader/Gallery on a Custom Post Type Edit Page

The current screen doesn’t appear to be set when that filter is run, so you cannot use that. Also, the $post actually refers to the attachment, not the post – so we can’t get the post typ fro that either…. So looking at the source code: http://core.trac.wordpress.org/browser/tags/3.3.2/wp-admin/includes/media.php The filter you are using is called by … Read more

can you set a default value to a custom field

You can check it by adding a hook to save_post action. In this way all your posts will have default value for a custom field. add_action( ‘save_post’, ‘wpse8170_save_post’, 10, 2 ); function wpse8170_save_post( $post_id, WP_Post $post ) { if ( ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) || !current_user_can( ‘edit_post’ ) ) { return; } … Read more

Fatal error: Call to undefined function add_action() – an untouched problem

get_stylesheet_directory_uri() returns an URL. The requested file is called like any other publicly available resource: without the context of the include statement. This is like opening the PHP file in a browser directly. There is no WordPress context, and the functions add_action() or add_filter() are not defined. Use get_template_directory() in parent themes and get_stylesheet_directory() in … Read more

Function to check if author has posted within the last x days

Yes, it is possible and it is pretty small change in your code… get_posts() uses WP_Query, so you can use all params from this list: https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters So here’s your code after changes: $args = array( ‘post_type’ => ‘your_custom_post_type’, ‘author’ => get_current_user_id(), ‘date_query’ => array( array( ‘after’ => ‘- X days’, // <- change X to … Read more