How do I add an admin notice within javascript in the admin interface for posts?

Look at F:\sites\wp-git\wp-admin\js\common.js: $(‘div.updated, div.error’).not(‘.below-h2, .inline’).insertAfter( $(‘div.wrap h2:first’) ); If your notice has the class updated or error, it will be set after the first h2 automatically. When you create custom messages, make sure you are using one of these classes. Then you can just append them to body, and WordPress will move them to … Read more

PHP Notice: Undefined offset: 0

If $wp_query->post_count == 0 I cant see how $wpdb->get_results( $wp_query->request ) would return any posts. So basically $request = $wpdb->get_results( $wp_query->request ); contains nothing and $request[0] doesn’t exist. Ergo PHP Notice: Undefined offset: 0 It would be interesting to know, what this could is supposed to achieve.

Alter admin notices to remove message that contain a certain string

Yes, this is possible (but a pain). Admin messages are creating when WordPress runs this line in admin-header.php: do_action( ‘admin_notices’ ); The action called before this one is: do_action( ‘in_admin_header’ ); So, we can hook in there and run some code to make some changes to filter out messages before WordPress can render them. First … Read more

Admin Notices don’t display on the admin screen for certain post

I found the answer. Notices in the Block Editor would require JavaScript code. ( function( wp ) { wp.data.dispatch(‘core/notices’).createNotice( ‘error’, // Can be one of: success, info, warning, error. ‘Error Message.’, // Text string to display. { isDismissible: true, // Whether the user can dismiss the notice. // Any actions the user can perform. actions: … Read more

Notices in the Block Editor with multiple lines

The 3rd parameter for the function accepts a private option named __unstableHTML which if true, then enables HTML in the notice message/content: createNotice( ‘success’, ‘Post published.<br /> Line 2. Should work in WordPress 5.8.’, { __unstableHTML: true, // true = allows HTML; default false isDismissible: true, actions: [ … ], } ) However, in the … Read more

Is there a way to hook into the update-core page for custom messages?

There is an action, ‘core_upgrade_preamble’, which can be added to output anything you would like at the bottom of the upgrade-core page. For example, try: add_action(‘core_upgrade_preamble’, ‘add_custom_upgrade_core_message’); function add_custom_upgrade_core_message(){ echo “<p>HI THERE</p>”; } That should work to meet your needs.

Notices on the front-end

You could filter the_content: add_action( ‘post_updated’, ‘wpse105892_add_message’, 10 ); function wpse105892_add_message() { add_filter( ‘the_content’, ‘wpse105892_display_message’ ); } function wpse105892_display_message( $content ) { // remove the action once it’s run remove_action( ‘post_updated’, ‘wpse105892_add_message’, 11 ); $content = “<div class=”your-message”>You did it!</div>\n\n” . $content; return $content; }

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