Month: October 2017

wordpress

Ajax return 0 in wordpress

Use echo instead of return a value from ajax function . { echo ‘locked’; die(); }

wordpress

How to add a new user meta field for all users in wordpress

$users = get_users(); foreach( $users as $user ) { $uid=$user->ID; add_user_meta($uid, ‘newfield’,’0′); } }

wordpress

Adding a meta data once a new user is created in wordpress?

Add Custom User Meta During Registration in WordPress add_action( ‘user_register’, ‘bonus_point_for_new_user’); function bonus_point_for_new_user( $user_id ) { add_user_meta($user_id, ‘newfield’,’0′); }

wordpress

Undefined message showing while new category adding?

Check whether is there any space before or after php opening and closing tag respectively in functions.php. If not deactivate each plugin and identify which plugin causes the issue, Then remove the extra space in that plugin after php closing tag.

wordpress

How to add extra fields to taxonomy in wordpress?

To add extra fields to taxonomy or category use below hook: add_action(‘categoryname’_add_form_fields,’function_name’); Sample: function add_extra_fields() { ?> <div class=”form-field”> <input type=”text” name=”term_meta[wh_meta_title]” id=”term_meta[wh_meta_title]”> </div> <?php } function edit_extra_fields($term) { } function save_extra_fields($term) { } add_action(‘product_cat_add_form_fields’, ‘add_extra_fields’); // For ‘product_cat’ add_action(‘product_cat_edit_form_fields’, ‘edit_extra_fields’); add_action(‘edited_product_cat’, ‘save_extra_fields’);

Php

How to create a file and include in php code?

$file_var= fopen(“newfile.html”, ‘w’); fwrite($file_var= , $html_elements); fclose($file_var); To use this file in html code: include(“newfile.html”);

Plugin developement Tips

How to get the current plugin folder url in WordPress?

plugin_dir_url( )  function is used to get the current url. Sample: $imgurl=plugin_dir_url( __FILE__ ).”placeholder.png”;

Plugin developement Tips

How to get the plugin folder path in wordpress?

echo $plugin_folder= plugins_url(); To get any specific file inside plugin directory use : Here getting path of file ‘widget_newslider11123.html’ insde plugin “books” echo plugins_url(‘books/widget_newslider11123.html’); Reference : https://codex.wordpress.org/Function_Reference/plugins_url

Plugin developement Tips

How to get the current plugin folder path in WordPress?

Current plugin folder path : plugin_dir_path( __FILE__ ) To include a file in this path: include(plugin_dir_path( __FILE__ ).”widgetfile.html”);

wordpress

how to create a menu in dashboard for plugin?

add_action(‘admin_menu’, ‘avg_rate_add_page’); function avg_rate_add_page(){ // Add main menu add_menu_page(‘Bonuspoints’, ‘Bonus point’, ‘administrator’, ‘avg_rate_page’,’avg_rate_options_settings’,’bonus.jpg’, ‘manage_options’); // Add Sub menu add_submenu_page( ‘avg_rate_page’, ‘Add points’, ‘Add points’, ‘manage_options’, ‘avg_rate_add_points’, ‘myplguin_admin_sub_page’ ); } function avg_rate_options_settings(){ /* code for main menu*/ } function myplguin_admin_sub_page(){ /* code for sub menu*/ } For deatils about menu creation arguments : https://codex.wordpress.org/Administration_Menus

Load More