WordPress Rest API custom endpoint optional param

You should put the named parameters of the route regex into an optional capturing group: register_rest_route( ‘api’, ‘/animals(?:/(?P<id>\d+))?’, [ ‘methods’ => WP_REST_Server::READABLE, ‘callback’ => ‘get_animals’, ‘args’ => [ ‘id’ ], ] ); The second parameter is simply a regex, thus you can use normal regex logic to make it more complex

Programmatically add a Navigation menu and menu items

I might be misunderstanding you, but why not use wp_create_nav_menu()? E.g., this is what I do to create a custom BuddyPress menu when I detect BP as active: $menuname = $lblg_themename . ‘ BuddyPress Menu’; $bpmenulocation = ‘lblgbpmenu’; // Does the menu exist already? $menu_exists = wp_get_nav_menu_object( $menuname ); // If it doesn’t exist, let’s … Read more

How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?

The way to do this is to use the ‘admin_enqueue_scripts’ hook to en-queue the files you need. This hook will get passed a $hook_suffix that relates to the current page that is loaded: function my_admin_enqueue($hook_suffix) { if($hook_suffix == ‘appearance_page_theme-options’) { wp_enqueue_script(‘my-theme-settings’, get_template_directory_uri() . ‘/js/theme-settings.js’, array(‘jquery’)); wp_enqueue_style(‘my-theme-settings’, get_template_directory_uri() . ‘/styles/theme-settings.css’); ?> <script type=”text/javascript”> //<![CDATA[ var template_directory … Read more

Using CloudConvert API in WordPress

Just tested on my end, and it’s working fine. Looks like something went wrong with the installation. Here are steps to follow to get it working: In the plug-in root directory create composer.json file with the following content: { “name”: “Example Application”, “description”: “This is an example”, “require”: { “cloudconvert/cloudconvert-php”: “2.2.*” } } run composer … Read more

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