wp_insert_post: array only. wp_update_post: array|object (?)

Array’s are technically preferred for both, but it actually doesn’t matter that much. PHP is not casting the object to an array, worpress is. wp_insert_post(), like a lot of wordpress functions, runs it’s “array” parameter through wp_parse_args() which will cast an object passed to it to an array and will always returns an array. You … Read more

Print Dashboard submenu name and filename

If you want them in an unordered list: echo “<ul>\r\n”; foreach ( $submenu as $group => $item ) { foreach ( $submenu[$group] as $key => $value ) { echo “<li>” . $submenu[$group][$key][0] . ” > ” . $submenu[$group][$key][2] . “</li>\r\n”; } } echo “</ul>”; This results in: <ul> <li>Home > index.php</li> <li>Updates > update-core.php</li> <li>Library … Read more

Remove all removed pages from wordpress

You must use wp_delete_post() with second parameter set to true. The post will be completely deleted, not trashed. // Use $args to get the pages you created previously // See https://developer.wordpress.org/reference/functions/get_pages/ $pages = get_pages( $args ); if( $pages ) { foreach( $pages as $page ) { wp_delete_post( $page->ID, true ); } } After that, you … Read more

Displaying “One Time” Notification in Plugins

The idea is that you need to save_errors or update the option that has the errors/notices whenever you want. As soon as its output once by admin_notices it will be cleared. /** * Sample_Notice_Handling */ class Sample_Notice_Handling { public static $_notices = array(); /** * Constructor */ public function __construct() { add_action( ‘admin_notices’, array( $this, … Read more

plugin add action hook is not working :

Nothing is wrong with your code. Just change the $Wp_Admin_Bar to all lowercase function wp_add_google_link(){ global $wp_admin_bar; var_dump($wp_admin_bar); $wp_admin_bar->add_menu(array( ‘id’=>’google_analytics’, ‘title’=>’GoogleAnalytics’, ‘href’=>’https://google.com/analytics’ )); } add_action(‘admin_bar_menu’,’wp_add_google_link’);

Cannot change caption for a plugin

You just changed the default value for $top_text. Modifying a plugin directly like that is not a good idea, because the changes will be lost when updating. There’s quite a bit more code in that plugin, and going through it, I see that there is an options page where that value is set. It seems … Read more