How can you set maximum width for original images?

Posted by Prem Tiwari | Updated on | WordPress


How can you set maximum width for original images. I was able to solve it using the following code:

How to use wpLink without editor?

Posted by Prem Tiwari | Updated on | WordPress


There is not ethical way of doing this. But still there is a way to do this. WordPress wrote wpLink script keeping in mind that editor is there but still WordPress handle when editor is …

Symbolic Links on dev box with plugins and stylesheets

Posted by Prem Tiwari | Updated on | WordPress


Symbolic Links on dev box with plugins and stylesheets. As you can see, the plugin URL is correct except for the real path stuck in the middle. We can filter the function responsible for generating …

How does WordPress handle permalink?

Posted by Prem Tiwari | Updated on | WordPress


The redirect_canonical function in /wp-includes/canonical.php is called on any given URL and will attempt to best-guess the URL the user wanted, and redirect them to there, when a URL does not exist. It has a …

Is there a is_user_logged_in() for multisite?

Posted by Prem Tiwari | Updated on | WordPress


Is there a is_user_logged_in() for multisite? The way users work in a multisite scenario is that there is a single pool of users, who are then associated with blogs. So, logged in status is common …

add_role() run only once

Posted by Prem Tiwari | Updated on | WordPress


add_role() run only once. As for best practice run once, if in a plugin you should use register_activation_hook and for any thing else i use a simple custom made conditional function:

Use REGEXP in WP_Query meta_query key

Posted by Prem Tiwari | Updated on | WordPress


Use REGEXP in WP_Query meta_query key. Your answer is perfect working in the first array lvl, for example:

Force category choice before creating new post?

Posted by Prem Tiwari | Updated on | WordPress


I solved this by hooking into post-new.php, and checking for a category_id request parameter. If it does not exist, I display a form with a category dropdown that submits back to this page, and then call exit() so the regular …

Custom Post Type Plugin: Where Do I Put The Template?

Posted by Prem Tiwari | Updated on | WordPress


You can use the single_template filter to switch out the template. In your callback, see if the theme provided a template for the post type, if it did, do nothing. Alternatively, you can use a …

Filter by one custom field, order by another?

Posted by Prem Tiwari | Updated on | WordPress


You could use the query to filter the content as you intended by using the ‘meta_query’ with filtering options, and for the order part, just add/modify the following parameters: 1. ‘orderby’ => ‘meta_value’ 2. ‘meta_key’ …

Hide other users’ posts in admin panel

Posted by Prem Tiwari | Updated on | WordPress


Hide other users’ posts in admin panel. Use the below example code in your functions.php file:

ancestorInheritedElementForWidgetOfExactType is deprecated

Posted by Prem Tiwari | Updated on | WordPress


Use context.getElementForInheritedWidgetOfExactType<_BlocProviderInherited<T>>().widget and it should work. As far as benefits go, the documentation basically states the same though someone can correct me but I don’t see any difference. You should be able to get rid of the _typeOf …

Where can I find documentation on what characters are allowed in user names and why?

Posted by Prem Tiwari | Updated on | WordPress


I don’t think there’s any official documentation about that, but you can have a look at the sanitize_user function in wp-includes/formatting.php: You could hook into that function and override the default behavior with your own.

Is it possible to override the result of get_template_part()?

Posted by Prem Tiwari | Updated on | WordPress


I think it’s not exactly possible the way you want to achieve. It’s really annoying to not getting a filter there to alter template files names. I have a workaround on it though. Let use …

How to store widget fields data as an array?

Posted by Prem Tiwari | Updated on | WordPress


Here is a very simple demo widget: