Open media box library from link

By enququing an JS file we can do like this: <img src=”#” id=”img-src”> <a href=”#” id=”img-upload”>Add Image</a> Content of JS file jQuery(document).ready(function(e){ e.preventDefault(); jQeury(‘#img-upload’).click(function(){ var upload = wp.media({ title:’Choose Image’, //Title for Media Box multiple:false //For limiting multiple image }) .on(‘select’, function(){ var select = upload.state().get(‘selection’); var attach = select.first().toJSON(); console.log(attach.id); //the attachment id of … Read more

Sending Parameter Failed

When an action is defined, the parameters passed to the callback are defined as well. For example, you can define an action with 4 parameters: $a = 1; $b = 2; $c = 3; $d = 4; do_action( ‘name_of_my_action’, $a, $b, $c, $d ); Then, when you hook in that action, you can tell how … Read more

_e in wordpress +

You can write like below: <?php /* translators: %s: home page URL */ printf( __( ‘We are sorry, but there is nothing here! You might even call this a 404 Page Not Found error message, which is exactly what it is. The page you are looking for either does not exist, or the URL you … Read more

Only admin should run wordpress plugin shortcode

Fatal error: Call to undefined function wp_get_current_user() This can be fixed by declaring check_user_role only when WP is ready, hooking into wp (to use WordPress functions and methods) or performing other workaround. Simply check if manage_options capability is there for the user too ( or verify if administrator is in the roles list in_array( “administrator”, … Read more

Submitting a plugin form to database in admin page

[UPDATE] You should have the page divided in two section- 1. One dealing with AJAX request and Post Method 2. Displaying form data Here is outline <?php if (strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) == ‘xmlhttprequest’ or $_SERVER[‘REQUEST_METHOD’] == ‘POST’){ // Process AJAX Request or POST Method } if (strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) != ‘xmlhttprequest’){ // HTML Code here which will not be … Read more