Articles of plugin development

Delay JavaScript files from loading

I need to delay AngularJS scripts from running so I can set up my application first. I need to initialize the application with ng-app=”app”. I want to add that attribute to the < body > < body ng-app=”app” >< /body > wp_enqueue_script(‘plugin-setup’, plugin_dir_url( __FILE__ ).’js/plugin-setup.js’, array(‘jquery’), null, true); plugin-set.js document.addEventListener(“DOMContentLoaded”, function(event) { document.getElementsByTagName(“body”)[0].setAttribute(“ng-app”, “app”); }); […]

Create a select metabox that the user can pupolate?

I have been working on a plugin that uses text area metaboxes on an options page to populate drop downs in the CPT area. I was with the help of some others able to get the list to show in the select boxes and was able to save the choice to the DB. So far […]

How to write to a separate PHP file in plugin settings

I need a way of taking a variable from a plugin’s settings and write it to a small key file located in the plugin’s directory. The entire contents of the key file is this: <?php $transaction_key = “npo7d3A0d2hhTYF5w9uo”; ?> I’ve tried to use file_put_contents, but I can’t get it to work. Anyone know how to […]

adding custom code as a wordpress plugin

i have written a small piece of code so when a user forgets and resets the password it will be emailed to the user currently i have added that code directly to the wp-login.php page do_action( ‘validate_password_reset’, $errors, $user ); if ( ( ! $errors->get_error_code() ) && isset( $_POST[‘pass1’] ) && !empty( $_POST[‘pass1’] ) ) […]

Get audio metadata on file upload

I am trying to fetch all audio metadata when I upload a file. This all happens in a plugin, and I currently use the add_attachment action to trigger my custom function : // link add_action( ‘add_attachment’, ‘add_metadata’ ); // Definition public function get_metadata( $post_ID ) { $post = get_post( $post_ID ); var_dump( $post ); var_dump( […]

Unable to give correct path in wordpress

Suppose their is a wordpress theme say zumper. Apart from files such as footer.php, header.php their are other folders such as layouts inc suppose I have a file america.php in layouts folder and york.php in inc folder what is the correct path and correct way to include york.php from inc folder to america.php, which is […]

WordPress Plugin Development- When our plugin functions call?

Assume that I have created plugin to include custom post type called site and plugin to search result. Assume I have added only following code to my plugin. function searchAll( $query ) { if ( $query->is_search ) { $query->set( ‘post_type’, array( ‘site’, ‘plugin’ )); } return $query; } add_filter( ‘the_search_query’, ‘searchAll’ ); When this function […]

Plugin base URL

In a question that is related to, but not the same as, How to link to images in my plugin regardless of the plugin folder's name plugin-folder/plugin-main-file.php plugin-folder/images/ containing all images plugin-folder/classes/ containing class definitions plugin-folder/classes/class1-files containing additional files for class 1 plugin-folder/classes/class2-files containing additional files for class 2 etc To access images, I can […]

Cleaning a filename after image sideloading a url that contains `%20`

Right now I’m creating a plugin to sideload images from an external source. The UI allows me to select files on the external server then downloads them via AJAX & media_sideload_image. Everything is working great. After the images is loaded I clean up the attachment’s title by replacing the dashes and underscores with spaces in […]

Plugin Development: Storing and Manipulating Data That Fits JSON in Database

I am new to WordPress plugin development but not web development in general. I have a website whose functionality I am trying to port over to WordPress for a client that needs it in a custom plugin and theme. On my other (non-Wordpress) website, which is a shop page, I have no way of editing […]