Hot answers tagged

9

You can filter 'wpmu_validate_user_signup' and check if the error code matches the 4 character warning. Then just unset the error code. Sample plugin: <?php # -*- coding: utf-8 -*- /* Plugin Name: Allow short user names for multi site. */ add_filter( 'wpmu_validate_user_signup', 'wpse_59760_short_user_names' ); /** * Allow very short user names. * *...


5

That number is taken from wp_max_upload_size(), and there is a filter: 'upload_size_limit'. See wp-admin/includes/template.php. So this should work (not tested): add_filter( 'upload_size_limit', 'wpse_70754_change_upload_size' ); function wpse_70754_change_upload_size() { return 1000 * 1024; }


5

To display 5 posts, say, use posts_per_page. See the Codex. $the_query = new WP_Query( array( 'brand' => 'sony-vaio','posts_per_page'=>5 ) );


5

You're looking in the wrong place. When a user first attempts to register, their username and email is processed and sanitized inside the register_new_user() function in wp-login.php. This is where you want to do your filtering. Before the user is created, WordPress will pass the sanitized user login, email address, and an array or errors through the '...


4

As @StephenHarris pointed out there's also the pre_get_posts filter. function hwl_home_pagesize( $query ) { if ( is_category( 9 ) ) { // If you want "posts per page" $query->query_vars['posts_per_page'] = 1; return; } if ( is_category( 'movie' ) ) { // If you want "showposts" $query->...


4

You can use the pre_get_posts hook (conditionals are available): function wpse47875_change_posts_per_page( $query ) { //Only alter main query. This only works for 3.3+ if( ! $query->is_main_query() ) return; if ( is_category('9') ){ //Display 4 posts for category 1 $query->set( 'posts_per_page', 4); } } ...


4

There are some restrictions (caused by lengths of some columns in database). Taxonomies Taxonomy name - 32 characters Term name (and term slug) - 200 characters Posts Post type name - 20 characters Post name (slug) - 200 characters Meta key - 255 characters Options Option name - 64 characters Comments Commenter email - 100 characters ...


4

Build an array of categories: foreach ($categories as $category) { $cat[] = $category->cat_ID; } Then pass that to the query: $args=array( 'category__in' => $cat, 'order' =>DESC, 'post__not_in' => array($post->ID), 'posts_per_page'=>2, ); In other words, put the query after the foreach, not inside of it.


3

I took the example code from the Wordpress user_has_cap filter codex page and modified it. Add this code to your theme functions.php: function restrict_editing_old_posts( $allcaps, $cap, $args ) { // Bail out if we're not asking to edit or delete a post ... if( ( 'edit_post' != $args[0] && 'delete_post' != $args[0] ) // ... or user is admin ||...


3

first add this function to your functions.php file function max_title_length($title){ $max = 20; return substr( $title, 0, $max ). " &hellip;"; } then before the loop of the code you linked add this line to hook the above function: add_filter( 'the_title', 'max_title_length'); and after the loop remove this filter: remove_filter( '...


3

In the form you have posted this is more of PHP question - you could use strlen() functions to determine length of original title and apply ellipsis conditionally. However in WP context you should consider using wp_trim_words() since trimming based on words looks tidier and it will take care of appending string of your choice whet cutting.


3

I think the answer is in the source. $username = wp_strip_all_tags( $username ); $username = remove_accents( $username ); // Kill octets $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username ); $username = preg_replace( '/&.+?;/', '', $username ); // Kill entities // If strict, reduce to ASCII for max portability. if ( $strict ) $...


3

As you can see in the WordPress Option Reference, there's an option called users_can_register. You can - per default - set it in your (network-)sites settings. 1 => Yes 0 => No As usual: There's a filter to intercept that from a plugin. "option_{$option_name}" So you can simply attach a callback to this filter and check the amount of users with a ...


3

First, please make sure you understand the difference between the_excerpt and the_content. You are asking about the_excerpt but I suspect that you might actually mean the_content. That said... You can filter the the_excerpt function with a filter of the same name. add_filter( 'the_excerpt', function ($excerpt) { return substr($excerpt,0,strpos($...


3

I'm not really sure which is the real problem with code you posted, however I cant understand why use 2 functions when one is enough... add_filter( 'wp_handle_upload_prefilter', 'limit_uploads_for_user_roles' ); function limit_uploads_for_user_roles( $file ) { $user = wp_get_current_user(); // add the role you want to limit in the array $limit_roles =...


3

You can approach this by first using a database query to count the number of pages that are already using the template: $query = "SELECT COUNT(*) as total FROM prefix_posts as p JOIN prefix_postmeta as m ON p.ID = m.post_id WHERE p.'post_type' = 'page' AND p.'post_status' = 'publish' AND m.'meta_key' = '_wp_page_template' AND m.'...


2

You can use my plugin Posts Creation Limits which has a per user, per role, per post type, per post status limiting system and combined with its post_creation_limits_custom_checks action hook and check if the user has created a post that day already - if so: show the the "limit reached message". For example: add_action( 'post_creation_limits_custom_checks', ...


2

The problem is that the_excerpt() strips all HTML. There's a good reason for this: what if the 49th word of a 50 word excerpt was the first word of a bulleted list? Or the second word in an <h1>? The way I would work around this is by using post thumbnails. These allow you to have an image you can choose to display at different sizes (or not at all) ...


2

You could pull all of the comments by current user and loop over them to see how may where today or you can create a custom sql Query to select just the count of comments for the last 24 hours, something like this: global $wpdb,$current_user; $sql = $wpdb->prepare(" SELECT count(*) FROM wp_comments WHERE comment_author = '%s' AND ...


2

As there can be more than one error for user names, the accepted answer could remove errors we would want to preserve. For example entering a user name of 123 would now pass whereas it should presumably still give the error message 'Sorry, usernames must have letters too!' Modified sample code to fix this: /* Plugin Name: Allow short user names for multi ...


2

for ($i=1; $i <= min($pages,10); $i++)


2

This seem to work. Put in your functions.php: add_filter('pre_get_posts', 'limit_pages'); function limit_pages($query) { $query->max_num_pages = 5; if ($query->query_vars['paged'] > 5) { $query->query_vars['paged'] = 5; $query->query['paged'] = 5; } return $query; } But I guess you would still need some ...


2

The expected behavior of posts_per_page is to NOT count sticky posts. This can be resolved with 'ignore_sticky_posts' => 1, but then the posts don't stick to the top of the menu. (In the trac ticket for sticky posts this issue is discussed.) There are some workarounds like this one, but they all feel a bit hacky to me. Personally I try to just deal with ...


2

Simple solution is to add a maxlength attribute to the textarea field. For example <textarea maxlength="140"> </textarea>


2

I always have the same problem with post excerpt, post content. There're various hooks and functions for this purpose, like @kaiser pointed out. But sometimes they don't do exactly what I want. Here's my solution, I write my own function that take the post content, and truncate it into specified number of words: function wpse69204_excerpt( $num_words = 20, ...


2

We had a similar problem where we needed to give access to partners and "membership" or "subscription" plugins seemed to offer what we needed. The problem we had was that the plugins we found were all for-pay, not free or freemium. Understanding this, the MagicMembers and aMember Pro plugins both had functions that could prevent access sharing. I'm sure ...


2

Adjust the amount of visible comments in the Screen Options:


2

You can use something like jQuery Simply Countable plugin and attach it to excerpt input. Limit_Excerpt_Words::on_load(); class Limit_Excerpt_Words { static function on_load() { add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts' ) ); } static function admin_enqueue_scripts() { global $hook_suffix;...


2

The warning notice gets dispatched by the function wp_check_post_lock. The following redirects the user back to the post listing screen if someone else is editing it. add_action( 'load-post.php', 'redirect_locked_post_wpse_95718' ); function redirect_locked_post_wpse_95718() { if( isset($_GET['post'] ) && wp_check_post_lock( $_GET['post'] ) ) ...


2

Piggybacking off Kaiser's answer: add_filter( 'option_users_can_register', 'limit_total_users' ); function limit_total_users( $option ) { // Registration turned off manually. Nothing to do here. if ( 0 === $option ) return $option; $user_count = count_users(); // Abort if we're above the limit if ( $user_count['total_users'] &...



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