How to output message during plugin activation

For testing purposes you can use the log system (php_error.log): error_log(‘Plugin activated’, 0); // Check for DB table existance if(!$this->hasDBTable()){ error_log(‘Database not present’, 0); if($this->createCELabelsDBTables()){ error_log(‘Database was created.’, 0); } else { error_log(‘Error creating the CE Labels Plugin db tables!’, 0); } } else { error_log(‘Database OK’, 0); } To output error to the user … Read more

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!

how to create child WordPress plugin

the Best way to do this is have your X plugin made with its own hooks for actions and filters so new plugins (in your case Y) could interact with plugin X’s functions and data. Defining your own hooks is fairly easy and simple. Action Hook from the codex: Actions are the hooks that the … Read more