manage_posts_custom_column, showing serial number using increment in loop

This code will add an Index value to each post which is determined by $wp_query->current_post, the number of posts per page, and the current page being viewed. add_filter( ‘manage_posts_columns’, ‘wpse240648_manage_posts_columns_index’); function wpse240648_manage_posts_columns_index($columns) { $columns[‘index’] = __( ‘Index’, ‘your-text-domain’ ); return $columns; } add_action( ‘manage_posts_custom_column’, ‘wpse240648_manage_posts_custom_column_index’, 10, 3 ); function wpse240648_manage_posts_custom_column_index( $column, $post_id ) { if … Read more

WP REST API V2 – Add user data to response

Solution A – Prepare User Response You can filter the response for a user to include any property you want with rest_prepare_user. add_filter( ‘rest_prepare_user’, function( $response, $user, $request ) { $response->data[ ‘first_name’ ] = get_user_meta( $user->ID, ‘first_name’, true ); $response->data[ ‘last_name’ ] = get_user_meta( $user->ID, ‘last_name’, true ); return $response; }, 10, 3 ); Solution … Read more

WordPress not working on localhost

1) Make sure the wp-config.php doesn’t have multisite reference settings such as define(“DOMAIN_CURRENT_SITE”, “somesite.com” );. If it does, delete these settings 2) If you have updated siteurl and home settings in the *_options table to use local settings and it still doesn’t work, then 3) Delete all themes but a basic one (twentytwelve, twentythirteen,…) and … Read more

How plugins_loaded works?

Use your class definition in a separate file, say in /your-plugin-dir/classes/my-gateway.php like usual: <?php class my_gateway extends WC_Payment_Gateways { //code } ?> Then use this CODE to include the file on plugins_loaded action from your main plugin file: add_action(‘plugins_loaded’, ‘WC_test_gateway_plugin’); function WC_test_gateway_plugin() { require_once plugin_dir_path( __FILE__ ) . ‘classes/my-gateway.php’; // instantiate your class here or … Read more

Customizer: widget-synced triggers twice

The reason for this is that the widget will run its update logic on keydown and also on change for a given input element. See https://github.com/WordPress/wordpress-develop/blob/4.7.2/src/wp-admin/js/customize-widgets.js#L891-L907 There are some tradeoffs made when widgets were added to the customizer to bring these PHP-driven interfaces into a JS-driven context. It wasn’t perfect and so this is part … Read more

Using the default wordpress uploader inside plugin

have you search in other question? this is the jquery script to call media uploader if u click a element media button var $j = jQuery.noConflict(); function call_media_library() { var media_uploader; $j(document).on(‘click’, ‘.video_media_btn’, function(e){ e.preventDefault(); var btn_uploader = $j(this); if (media_uploader) { media_uploader.open(); return; } media_uploader = wp.media({ title: ‘Upload media’, //you can change type … Read more

$content variable – Is this a reserved variable for a WordPress function? – php / wordpress

$content – is not reserved in WordPress, it can be used. In the function the_content () – a variable is used, but it is only available in this function. The code of the function itself: https://core.trac.wordpress.org/browser/tags/4.7/src/wp-includes/post-template.php#L230 Scope of variables in php: http://php.net/manual/en/language.variables.scope.php