Extending the site search to include a single custom field

I managed to resolve by extending the query function extend_search( $search, &$wp_query ) { global $wpdb; if ( empty( $search )) return $search; $terms = $wp_query->query_vars[ ‘s’ ]; $exploded = explode( ‘ ‘, $terms ); if( $exploded === FALSE || count( $exploded ) == 0 ) $exploded = array( 0 => $terms ); $search=””; foreach( … Read more

Override a plugin class function

Finally, I figured out how to solve my problem: class Import_Facebook_Events_Facebook_Ext extends Import_Facebook_Events_Facebook { function get_location( $facebook_event ) { if ( !isset( $facebook_event->place->id ) ) { $facebook_event->place->id = ”; //return null; } //other code here return $event_location; } } $new_ife_events = run_import_facebook_events(); $new_ife_events->facebook = new Import_Facebook_Events_Facebook_Ext(); A question: the last two code lines must be … Read more

Add new user : make the fields First Name and Last name required

If you were looking to make the fields required in the WordPress admin form for adding new user as i understood from your question, where the output is not filterable, you could basically do what you described (adding form-required) on browser side function se372358_add_required_to_first_name_last_name(string $type) { if ( ‘add-new-user’ === $type ) { ?> <script … Read more

Using add_filter() in Widgets

<?php /** * Display the actual Widget * * @param Array $args * @param Array $instance */ public function widget($args, $instance){ … $wcss = apply_filters( ‘my-filter-name’, $wcss ); … } ?> To create your own filter hook just use the function “apply_filters” then as you mentioned add a function in your constructor i.e. function __constructor() … Read more

How to create thumbnails for PDF uploads?

If I’m not totally mistaken, the code you have given on your update won’t work, because the file/mime type pdf isn’t supported by the WP_image_editor class called by wp_get_image_editor(). Creating a thumbnail from a uploaded pdf file can be achieved though. Below code gives you a insight in a possibility how to do it, I … Read more

How to add classes to images based on their categories?

This should hopefully do the trick: /** * Append the image categories to the current image class. * * @see http://wordpress.stackexchange.com/a/156576/26350 */ add_filter( ‘get_image_tag_class’, function( $class, $id, $align, $size ) { foreach( (array) get_the_category( $id ) as $cat ) { $class .= ‘ category-‘ . $cat->slug; } return $class; } , 10, 4 ); Testing … Read more