Tag Info

Hot answers tagged

13

You are acting on awfully big assumption that something like that would improve performance. Spoiler — no, it won't. The load process in very loose terms consists of: Optionally running code responsible for looking up definitions (autoload or custom). Parsing the file or retrieving results from opcode cache. Loading results to be used. The "autoload is ...


11

This is an alternative approach to @kaiser answer, that I found pretty fine (+1 from me) but requires additional work to be used with core WP functions and it's per-se low integrated with template hierarchy. The approach I want to share is based on a single class (it's a stripped-down version from something I'm working on) that takes care of render data for ...


9

Basic separated data structures To pass around data, you normally utilize a Model (that's the "M" in "MVC"). Let's look at a very simple interface for data. Interfaces are just used as "Recipes" for our building blocks: namespace WeCodeMore\Package\Models; interface ArgsInterface { public function getID(); public function getLabel(); } Above is ...


8

functional interpreted code will always be faster then OOP one. Compare function hello_mark() { echo 'hello mark'; } hello_mark(); with class mark { function say_hi() { echo 'hello mark'; } } $m = new mark(); $m->say_hi(); I think it is obvious what is faster to interpret and execute. People don't do OOP because it is faster, they do ...


7

Best of luck to you, but this won't improve performance in any real way. WordPress is indeed becoming more and more object oriented, over time and with incremental changes. Every update in the last 4 years has refactored some major piece of code into a more class oriented design. Nevertheless, OO and autoload and other things like this are not inherently ...


7

Here's an example of the data returned from the wp_get_update_data() function: Array ( [counts] => Array ( [plugins] => 3 [themes] => 2 [wordpress] => 0 [translations] => 0 [total] => 5 ) [title] => 3 Plugin Updates, 2 Theme Updates ) So the number of ...


7

If you look at the source code of get_the_archive_title(), you will see that there is a filter supplied, called get_the_archive_title, through which you can filter the output from the function. You can use the following to change the output on a category page add_filter( 'get_the_archive_title', function ( $title ) { if( is_category() ) { ...


7

If you need this to be a PHP solution. You could do something like this using 'the_content' filter. This will add the class name "content-img-wrap" to any paragraph that wraps only an image tag when Wordpress prints your post content. So this will not wrap a paragraph with an image and a span. See update if that is what your looking for. add_filter( ...


6

PHP has a function, get_included_files() that returns all the file have been includedduring a request. However, if you use that fucntion you obtain all the files required: WordPress core files, plugin files... You need a way to: filter out files that do not belong to theme and child theme (if any) include only files loaded after main template has been ...


6

As @cybmeta already pointed out, you are too early with your removal. So you have to defer the actual removal, for instance like so: add_action( 'after_setup_theme', 'wpdev_170663_remove_parent_theme_stuff', 0 ); function wpdev_170663_remove_parent_theme_stuff() { remove_action( 'after_setup_theme', 'et_pb_setup_theme' ); }


6

Try this: if ( has_excerpt( $some_post_id ) ) { // Do something here? } else { // Or here? } References: has_excerpt


6

Note that if any script in the header at all needs jQuery then it will bump it to header, regardless if it's changed to be enqueued for footer. So while changing it to be queued for footer makes sense it rarely works out when a lot of script stuff is going on.


6

wp_get_update_data() returns an array in this format counts plugins themes wordpress translations total title So, if you want total count, you need to use it like this $updates = wp_get_update_data(); echo $updates['counts']['total'];


6

You can use get_the_title() to return the current post title in the loop.


5

Via using the dynamic_sidebar() you can change/edit the widgets in the widgets area of the appearance settings. If you use the_widget() you hard code it straight to template so you need to modify the code to change what is displayed. Both have their uses. Too many sidebars tend to clutter the widgets area, but is very good for users that don't want to mess ...


5

You can extend the get_the_archive_title filter which I've mentioned in this answer add_filter( 'get_the_archive_title', function ($title) { if ( is_category() ) { $title = single_cat_title( '', false ); } elseif ( is_tag() ) { $title = single_tag_title( '', false ); } elseif ( is_author() ) { ...


5

You can hook onto pre_insert_term, check the taxonomy and whether or not the user has the specified role as follows: function disallow_insert_term($term, $taxonomy) { $user = wp_get_current_user(); if ( $taxonomy === 'post_tag' && in_array('somerole', $user->roles) ) { return new WP_Error( 'disallow_insert_term', ...


5

The is_login_page() function is taken from here function is_login_page() { return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')); } function my_redirect() { //if you have the page id of landing. I would tell you to use if( is_page('page id here') instead //Don't redirect if user is logged in or user is trying to sign ...


5

All you can do is bump the priority of your hook: add_action( 'wp_head', 'dns_prefetch', 0 /* Highest priority */ ); but does this put my code just after the start of tag? No, but it will output before any other function attached to wp_head i.e. other <link />'s, most stylesheets, plugin scripts etc. To put it right after <head> you'll ...


5

I am not sure why your query is returning more IDs than necessary. The $args for get_users look correct. By default get_users does not support orderby=rand, but you can overwrite that option. See below: function random_user_query( &$query ) { $query->query_orderby = "ORDER BY RAND()"; } // Usage: [random_users how_many = 3] add_shortcode( ...


4

You can make use of the conditional tag is_page_template() This Conditional Tag allows you to determine if you are in any page template. Optionally checks if a specific Page Template is being used in a Page. This is a boolean function, meaning it returns either TRUE or FALSE. You can try something like if( is_page_template( 'template-flat.php' ) ) { ...


4

Your problem isn't that you did the wrong thing, it's that you did it at the wrong time. When it happens is important, not where. In a child theme, the functions.php is loaded, then the parents, so you're doing this: Remove the first_paragraph function from the_content filter Add the first_paragraph function to the_content filter Clearly this is the ...


4

Add the following code to your functions.php: function allow_contributor_uploads() { $contributor = get_role('contributor'); $contributor->add_cap('upload_files'); } if ( current_user_can('contributor') && !current_user_can('upload_files') ) { add_action('admin_init', 'allow_contributor_uploads'); } This will add the upload_files ...


4

I doubt it would justify the effort of writing custom SQL queries for only 2500 posts. Within the wp_set_object_terms( $object_id, ... ) function we have: $object_id = (int) $object_id; so it's correct that it only takes a single post id as input. So you would need to loop over your $post_ids array but it might be sufficient to use the ...


4

You can set the expire date as post meta value. In single.php you can easily show that date by querying the post meta. See update_post_meta() and get_post_meta() Now, the second part of your question is pretty tricky. I can think of 2 solutions. Cron You can use wordpress cron to run at a time interval to check which post has been expired and ...


4

Simple answer, don't pass variables anywhere as it stinks of using global variables which is evil. From your example it seems like you are trying to do an early optimization, yet another evil ;) Use the wordpress API to get data which is stored in the DB and don't try to outsmart and optimize its usage as the API do more then just retrieving values and it ...


3

What about using the WordPress function get_ancestors(), which Returns an array containing the parents of the given object. To be exact an Array of ancestors from lowest to highest in the hierarchy We can easily create a function to return a list by using implode to do so: function wpse185971_get_ancestors_list( $object_id, ...


3

You can use PHP get method to process these variables. <?php if( $_GET['action'] == 'discussion' ) { ?> It's True. <?php } else { ?> It's False. <?php { ?>


3

get_the_utm_vars doesn't work like you think it does. A function cannot return more than one value. Right now, when the first return is reached, that value is returned and none of the following lines are ever reached. You could have get_the_utm_vars return an array of values instead: function get_the_utm_vars(){ $utm = array(); $utm['source'] ...


3

Change this line setcookie( 'cookiename', 'cookievalue', time() + 3600, 'mysite.net/sites/site1/', 'mysite.net/sites/site1/'); to setcookie( 'cookiename', cookievalue, time() + 3600, COOKIEPATH, COOKIE_DOMAIN);` COOKIEPATH and COOKIE_DOMAIN are WP constants now, but the codex is not updated yet.



Only top voted, non community-wiki answers of a minimum length are eligible