Can I access WordPress API’s from within plugin scripts?

I believe you’re using ajax refering the process_form.php. However the right way to access any ajax is through the wp-admin/admin-ajax.php. Pull all your code from process_form.php to a function (can be added on your main plugin file): function my_process_form() { //…code from process_form.php if ( ! $error ) { //your error boolean return wp_json_success(); //recommend … Read more

Undefined notice on unset field

The error is that you’re trying to read $value[‘kk_youtube’] when there is no kk_youtube key in the array (undefined index). Rather than use isset, use get_post_meta with the third argument “single” true: $youtube_link = esc_attr( get_post_meta( $post->ID, ‘kk_youtube’, true ) ); This is effectively the same as doing: $value = get_post_custom( $post->ID ); if ( … Read more

Rewriting URLs with a query string

First of all, you have to make sure to register your public query vars with WordPress so it recognizes your rewrite rule vars. Add this code on your functions.php file: add_rewrite_rule(‘^(tips)/([^/]*)/([^/]*)/?’, ‘index.php?name=$matches[1]&id=$matches[2]&filter_id=$matches[3]’,’top’); add_filter(‘query_vars’, ‘foo_my_query_vars’); function foo_my_query_vars($vars){ $vars[] = ‘id’; $vars[] = ‘filter_id’; return $vars; } After that, enter on your Permalinks Settings page to flush … Read more

How to add conent (text) to Add New pages form of admin in WordPress

The hook to use here is admin_notices. However in register_activation_hook and register_deactivation_hook it shouldn’t be used because these function run when plugin activates and deactivates instance. A workaround it we use add_option when plugin activates and delete_option when plugin deactivates. Here is the code. Hopefully you will understand it properly <?php function my_admin_notice() { $screen … Read more