How to get variables from fucntion.php to my plugin files

There is three way to use function.php file variable into plugin file. Using global. Make sure you globalize it first. global $my_variable; echo $my_variable; I recommend is using WordPress built-in filter mechanism add_filter. You add the filter in your functions.php file and apply it where needed. In functions.php: add_filter( ‘my_variable’, ‘return_my_variable’ ); function return_my_variable( $arg … Read more

Load custom template for specific GET parameter

Just found an pretty straightforward solution for this problem: add_action( ‘template_include’, ‘account_page_template’ ); function account_page_template( $template ) { if( isset( $_GET[ ‘account’ ] ) ) { return locate_template( array( ‘account.php’ ) ); } return $template; } But as it seems only natural to use some kind of permalink stucture for these kind of things here … Read more

REST API parameters not working with nginx

If your virtual host looks like this: try_files $uri $uri/ /index.php$args; change it to this: try_files $uri $uri/ /index.php$is_args$args; Adding $is_args (which will print a ? character if query arguments are found) will allow WordPress to properly receive and interpret the query parameters

WordPress ajax function parameter value not being passed

First of all you should read the codex on AJAX_in_Plugins Secondly you should look at wp_localize_script to get the value for the admin-ajax url to your javascript. $data = array( ‘ajax_url’ => admin_url( ‘admin-ajax.php’ ) ); wp_localize_script( ‘ajax-script’, ‘ajax_object’, $data ); In your javascript, you are then meant to reference the localized data jQuery(“.selectbox”).change(function(){ var … Read more

append url parameters to all links

1. Track Affiliate via Cookie To track the affiliate source you can use a Cookie for internal tracking. In that case you only need to modify external links. add_action( ‘plugins_loaded’, ‘so265278_affiliate_check’ ); function so265278_affiliate_check() { $is_affiliate = ! empty( $_GET[‘ref’] ); if ( $is_affiliate ) { setcookie( ‘affiliate’, $_GET[‘ref’], MONTH_IN_SECONDS ); } } Now you … Read more

Can we access the REST request parameters from within the permission_callback to enforce a 401 by returning false?

I’ve created a reduced test case that demonstrates that what you want to do is achievable: add_action( ‘rest_api_init’, function() { register_rest_route( ‘wpse/343039’, ‘route’, [ ‘methods’ => [ ‘POST’ ], ‘permission_callback’ => function( WP_REST_Request $request ) { if ( ‘1’ == $request->get_param( ‘param’ ) ) { return true; } else { return false; } }, ‘callback’ … Read more