Checking if a file is already in the Media Library

global $wpdb; $image_src = wp_upload_dir()[‘baseurl’] . “https://wordpress.stackexchange.com/” . _wp_relative_upload_path( $filename ); $query = “SELECT COUNT(*) FROM {$wpdb->posts} WHERE guid=’$image_src'”; $count = intval($wpdb->get_var($query)); You can use this at the top of your code. Then check the value of $count. If it’s 0, then you can continue adding the attachment

How can I load a page template from a plugin?

You can use the theme_page_templates filter to add templates to the dropdown list of page templates like this: function wpse255804_add_page_template ($templates) { $templates[‘my-custom-template.php’] = ‘My Template’; return $templates; } add_filter (‘theme_page_templates’, ‘wpse255804_add_page_template’); Now WP will be searching for my-custom-template.php in the theme directory, so you will have to redirect that to your plugin directory by … Read more

How Do I Use jQuery UI In My Plugin

Given that all of the libraries you need for the datepicker are bundled with WordPress and are registered with all of the appropriate dependencies, all you really need to do is: function enqueue_my_scripts_wpse_97533() { wp_enqueue_script(‘jquery-ui-datepicker’); } add_action(‘wp_enqueue_scripts’,’enqueue_my_scripts_wpse_97533′); If you then look at the source of the page you will see that jQuery, jQuery-UI, and jQuery-UI-Datepicker … Read more

what’s the meaning of the field wp_capabilities in table wp_usermeta

The wp_capabilities saves the value as serilized array, you can try it in your php or for this example here: http://blog.tanist.co.uk/files/unserialize/. The Code: a:1:{s:13:”administrator”;b:1;} Is: Array ( [administrator] => 1 ) Meaning the user is an administrator. You can add new roles to the database by running the function add_role, and only run it once!

Settings API updated messages won’t show if custom admin page not hooked into add_options_page()

Thanks Chip (excellent Settings API tutorial) and t31os (great snippet of code for quick testing) for both your suggestions. I did some further digging and found that the default messages can indeed be displayed if I hook into any menu but only if the function settings_errors() is called. For example, modifying t31os code as follows: … Read more

How to check uniqueness of plugin prefix?

You can use the WordPres Plugin Directory Slurper shell script by Mark Jaquith to download the the most recent version of all plugins from the WordPress.org repo. Once the plugins have been downloaded, you can grep for the plugin/hook prefix you want to check, e.g.: grep -r –include=*.php ‘wpseo_’ ./ Unzip the WordPres Plugin Directory … Read more

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