How do you render_callback for register_block_type to a method in another class?

Option 1 is the solution, here’s a smaller example: $obj = new Obj(); …. register_block_type( ‘my-plugin/my-block’, [ ‘editor_script’ => ‘editor-script-handle’, ‘render_callback’ => [ $obj, ‘block_save_function’ ] ] ); In that code [ $obj, ‘block_save_function’ ] is equivalent to $obj->block_save_function(…. The important thing to note, is that render_callback‘s value is a PHP callable type. You need … Read more

How to add pages to custom menus on the fly [duplicate]

I guess it doesn’t need anymore explanation: $mymenu = wp_get_nav_menu_object(‘Main Navigation Menu’); $menuID = (int) $mymenu->term_id; $myPage = get_page_by_title(‘About Us’); $itemData = array( ‘menu-item-object-id’ => $myPage->ID, ‘menu-item-parent-id’ => 0, ‘menu-item-position’ => 2, ‘menu-item-object’ => ‘page’, ‘menu-item-type’ => ‘post_type’, ‘menu-item-status’ => ‘publish’ ); wp_update_nav_menu_item($menuID, 0, $itemData);

Hook to get image filename when it is uploaded

The handle_upload hook is called after wp_handle_upload is run, and it sends in a named array consisting of ‘file’, ‘url’ & ‘type’. You could possibly use code like this to utilise it, depending on what you need to achieve: function process_images($results) { if( $results[‘type’] === ‘image/jpeg’ ) { // or /png or /tif / /whatever … Read more

how to include javascript file and css file in wordpress

WordPress already ships with jQuery. There is no need to include it in your theme. Javascript Let’s say your jquery.tabify.js file is located in /js/jquery.tabify.js in your theme. Include the following code in your functions.php file: function jquery_tabify() { wp_enqueue_script( ‘jquery-tabify’, get_template_directory_uri() . ‘/js/jquery.tabify.js’, array( ‘jquery’ ) ); } add_action( ‘wp_enqueue_scripts’, ‘jquery_tabify’ ); This will … Read more

Plugin development: How many plugin and WordPress version combinations to support?

Usually a plugin developed in WordPress version will run fine on several newer versions. What you need to care about is ‘deprecated` features/apis in WordPress. Any API in WordPress is not removed overnight, rather it remains deprecated for several versions. You will get such a list here: http://codex.wordpress.org/Category:Deprecated_Functions When you develop a plugin, you can … Read more