Customizing Text in WordPress's wp-signup.php - wordpress

I need to change the following default text on the WordPress multisite signup page (wp-signup.php):
"There is no limit to the number of sites you can have, so create to
your heart’s content, but write responsibly!"
...since this WordPress install will be limiting the number of sites a user can create.
Is it possible to override the content of this page without hacking the wp-signup.php file or dealing with .htaccess?
This WordPress install is being hosted by a third party service and it would be best if I could avoid dealing with modifying these files.

I've managed to hit on another solution. It turns out, that since the text on the wp-signup.php page is run through __(), you can alter it using the 'gettext' filter like so:
/**
* Modify default wp-signup.php text
*/
function themename_wp_signup_text( $translated_text, $untranslated_text, $domain ) {
global $pagenow;
if ( is_multisite() && $pagenow === 'wp-signup.php' ) {
switch ( $untranslated_text ) {
case 'Welcome back, %s. By filling out the form below, you can <strong>add another site to your account</strong>. There is no limit to the number of sites you can have, so create to your heart’s content, but write responsibly!' :
$translated_text = __( 'Welcome back, %s. By filling out the form below, you can <strong>add another site to your account</strong>. You can create a maximum of 5 sites. Remember to write responsibly or some junk! Ciao!', 'theme_text_domain' );
break;
}
}
return $translated_text;
}
add_filter( 'gettext', 'themename_wp_signup_text', 20, 3 );
...which is just for a theme, but you could do this in a plugin too.
So the text is technically filterable, but I'd say this is a huge hack though, but it'll do, and shouldn't have any consequences until that particular text changes in WordPress core...

As Dave Kiss said in his comment above, this string isn't filterable so you can't filter the text. The string isn't marked either so you can't use a translation file.
I suggest you open a WordPress Trac ticket requesting the text be marked or made filterable.
You can open a new ticket here: http://core.trac.wordpress.org/

Related

How to hide "Add Media" from frontend users?

I'm running a multi author's wordpress site, and users can post contents directly from the front end of my site.
My problem is this, file upload is directly allowed on the front end of my wordpress site.
I want a situation whereby, when users click on Add Media button from my site post submission form,
Instead of seeing this wordpress Add Media Library to select and upload media,
I want them to see this instead. Takes them straight to their device file.
Any code i can use to execute this on my wordpress site?
To hide “Add Media” from frontend users, you should limit access to the media library to administrator and editor roles only.
From WP Beginner, You’ll need to add the following code to your WordPress functions.php file or a site-specific plugin.
// Limit media library access
add_filter( 'ajax_query_attachments_args', 'wpb_show_current_user_attachments' );
function wpb_show_current_user_attachments( $query ) {
$user_id = get_current_user_id();
if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts
') ) {
$query['author'] = $user_id;
}
return $query;
}
This code uses current_user_can function to check if the user has the capability to activate plugins or edit other user’s posts. If they don’t, then it changes the query used to display media files and limit it to user’s ID.

How can I display Product Images to Logged In Users only, with Logged Out Users seeing an alternative image?

I would like to modify my WordPress/WooCommerce website, so that my Product Images have the following conditions:
Logged in site visitors:
I would like logged in visitors, to be able to see all of the WooCommerce Product Images.
Logged out site visitors:
I would like logged out visitors, to see an alternative image. Therefore, hide the Product Image. This alternative image, will be the same for every Product.
Firstly, you are going to need to create a Child Theme, for your WordPress/WooCommerce website.
Once created, simply insert the following code, into the functions.php file, within your Child Theme:
<?php
// Remove Default WooCommerce Product Images/Placeholders.
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
// Create conditional logic function.
function logged_in_images(){
// If site visitor is Logged in, display Default WooCommerce Product Images/Placeholder.
if ( is_user_logged_in() ) {
echo woocommerce_show_product_images();
}
// If site visitor is not logged in, display the following Image instead.
else {
echo '<img src=http://vaporcenter.be/theme/Wholesale/img/placeholders/default.jpg?1504084579>';
};
}
// We are inserting ('Hooking' into) the above function into where the Default WooCommerce Product Image/Placeholder was, before we removed it.
add_action( 'woocommerce_before_single_product_summary', 'logged_in_images', 20 );
?>
Be sure to replace http://vaporcenter.be/theme/Wholesale/img/placeholders/default.jpg?1504084579 with your desired image.
Don't forget, you can remove the comments (// ...) from the code. They are there, to just help explain what is happening.
I have tested the above code and it does work.
Best of luck!
If you receive an error
Step One: Using an FTP client, such as Filezilla, go into your Root Folder (Where you installed WordPress).
Look for a file entitled wp-config.php and drag this to your computer.
Open the file, using Notepad/Notepad++ and look for the line define('WP_DEBUG', false); and change 'false' to 'true'.
Drag the wp-config.php file back from where you got it from.
Refresh the page you are having an issue. You should then see an error message, which will be helpful in addressing how to resolve any issues.
Once you have resolved your issue, and your website is back in working order, head back into your wp-config.php and change 'true' back to 'false'.

How to customize Wordpress Theme before going live

Yesterday I installed a new theme on Wordpress on my self-hosted website. I am aware of the feature that allows you to preview a theme and have used it to select a new Theme that I want to install.
Problem
I do not want to interrupt normal operations of my website, but this new theme requires a lot of customization before it is ready to go. How do I do this?
My Crappy Solution
Is the only way to go about it to run a virtual server on my desktop? This seems tedious, not to mention all the errors I usually get when switching to the "real" server when doing this.
A better way?
I've been searching on SO as well as the WordPress Forum for an answer as to how to do this, but have come up short. I would have thought this is a common question. Maybe I'm using the wrong search terms [themes, customization, before installing]???
Any help is greatly appreciated! Thanks!
Ok, since your question is a pretty good one and probably not a few people are going through the same process when they decide to update their site, I decided to give a try to the get_stylesheet and get_template filter hooks. It turns out that with a very small plugin, you can easily enforce a specific theme(well in this case any logged-in visitor, but you can change this to use any logic you want) according to a specific rule/s.
Here's the code that you need to put in a file in your plugins directory:
<?php
/*
Plugin Name: Switch Theme
Description: Switches the theme for logged-in visitors, while keeping the current theme for everyone else. !!!NOTE!!! Please back-up your database prior using this plugin - I can't guarantee that it will work with any theme, nor that it won't break your site's set-up - USE AT YOUR OWN RISK(I did a quick test and it seemed to be fine, but haven't done extensive testing).
You don't need to switch to the desired theme before that - you want to keep active the theme that you will display to your visitors - the one that you will see will be used programatically.
Before activating the plugin, change the line that says `private $admin_theme = '';` to `private $admin_theme = 'theme-directory-name';` where "theme-directory-name" is obviously the name of the directory in which the desired theme resides in.
*/
class MyThemeSwitcher {
private $admin_theme = '';
function MyThemeSwitcher() {
add_filter( 'stylesheet', array( &$this, 'get_stylesheet' ) );
add_filter( 'template', array( &$this, 'get_template' ) );
}
function get_stylesheet($stylesheet = '') {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $stylesheet;
}
function get_template( $template ) {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $template;
}
}
$theme_switcher = new MyThemeSwitcher();
So - first of all BACKUP YOUR DATABASE! I tested locally with Twenty Eleven being the default theme and a basic framework theme as my custom theme - the theme options and navigation menus were saved properly.
Then all you need to do is to update the file(change the line that says private $admin_theme = ''; to private $admin_theme = 'theme-slug'; where theme-slug is the name of the directory in which the theme you want to use is).
Also - you won't be able to change the Front page and Posts page options, without this affecting the live site, nor will you be able to change the any shared components that both themes use(Site name, Front Page, Posts page, Posts Per Page, etc options, content and so on).
So if you have no clue whether this solution is for you - well, it depends.
If both themes are not relatively complex, then most-likely you should be able to use this hack. If they are though maybe you should do a second installation of your website as others suggested - I think that a second installation in either a sub-domain or a sub-directory would be the best option for you(simply because moving a multisite database is more complex than moving a normal WP database).
I'd setup local apache server with a wordpress installed to customize and test a new theme. When you finished customizing it then you can upload the theme to your live site and activate it. If there are settings that you need to set in the dashboard then you probably will have to adjust them again. That's one way to test/customize a theme before putting it live.
You could create a network (make WordPress multisite with define('WP_ALLOW_MULTISITE', true);, see : http://codex.wordpress.org/Create_A_Network) and then create one sub-site, then turn it "off" with a Maintenance plugin so it is not accessible to users not logged in as admin, export your posts & data from main blog, import them in sub-blog with WordPress default importer, then apply your new theme to this sub-blog and work on it. When everything satisfies you, apply the theme to the main site and deactivate subsite.

Wordpress Auto Draft disabling

I am using Wordpress v.3.3.1 With Multisite management on.
I am trying to disable the auto draft function, but it seems that I have tried everythig.
What I have tried:
define('WP_POST_REVISIONS', false);
define('WP_POST_REVISIONS', false);
Didn't work.
I have tried to remove the auto_save lines in post-new.php, post-php. Both in wp-includes and in wp-admin. Didn't work.
I have also tried several plugins, but they won't do it! Any idea why?
I notice that you are asking about disabling Auto-Drafts and NOT Auto-Save.
You cannot disable Auto-save, but you can achieve a similar affect by setting a long interval, for example:
define( 'AUTOSAVE_INTERVAL', 3600 ); // Default is 60
(You'd add it in your WordPress site's wp-config.php file.)
As for Auto-Drafts, you don't want to disable them. They are there for an important reason. Let me grab a quote or two for ya...
Samuel 'Otto' Wood, Tech Ninja at Audrey Capital (Matt Mullenweg's angel investment company), says:
Auto-drafts exist because of the fact that multiple users can create new posts at the same time. If two people enter post-new at roughly the same moment, then have their first autosaves occur nearly simultaneously, then there is a race condition that can cause one of them to get back the wrong post ID, which will cause a post to be overwritten/lost when they then continue editing the post.
The auto-draft creates the post and gets the ID of the new post before the editing screen is displayed, thus preventing two simultaneous authors from accidentally having the same post ID in the data in their browser.
Andrew Ozz, who worked on WordPress' TinyMCE integration, says:
This also makes it possible to upload images before the first draft is saved and they will be properly attached to the new post.
And lastly:
Auto-drafts are automatically deleted after 7 days of going unused. They're self-cleaning, basically. No need to worry about them.
A) Set it in your wp-config.php file. Else it won't work.
define( 'AUTOSAVE_INTERVAL', 3600 ); // autosave 1x per hour
define( 'WP_POST_REVISIONS', false ); // no revisions
define( 'DISABLE_WP_CRON', true );
define( 'EMPTY_TRASH_DAYS', 7 ); // one week
Open wp-config.php located in your WordPress root directory and add following code:
define('WP_POST_REVISIONS', false );
before of require_once ABSPATH . 'wp-settings.php'; or and top of the file.
For guys who use WordPress 5.0+ version with Gutenberg Editor, the below code snippet works to disable auto drafting/saving
/**
* Disables auto saving feature for Gutenberg Editor (set interval by 3600s)
*/
add_filter( 'block_editor_settings', 'rsm0128_block_editor_settings', 10, 2 );
function rsm0128_block_editor_settings( $editor_settings, $post ) {
$editor_settings['autosaveInterval'] = 3600;
return $editor_settings;
}
I think disabling it is not good (for example, when you parallely try to publish 2 posts, then there may be problems). So, instead, of disabling:
Method 1)
disable them slightly (without CORE-modifications), see this answer.
Method 2)
just clean them using this code or good plugin WP Clean Up

What would cause edit buttons for plugins in wordpress plugins page to disappear?

in the plugins page, under each plugins' name usually there are buttons/links like "Deactivate | Edit | Settings". Recently on one of my sites the "Edit" (and "Settings") button has disappeared. I have just "Deactivate" or "Activate | Delete".
My question is - what could cause this?
I am logged in as an administrator, so I should see the buttons. I suspect that something might have vent wrong with the installation of the last plugin but I am not sure.
Is there some scenario when these buttons get disabled (hidden) or do I have a bug / error?
EDIT:
This is happening on the server. I also have the exact same files (just checked with a comparer) running on my local computer, where plugins have all the buttons. I am now looking in the DB to find differences, but so far have not found anything significant.
Sounds like a file permissions error, make sure the user the web server is running as (typically www-data or similar) has write permissions to the plugin files.
Those "buttons" are called "plugin_action_links" and are/can be set by the plugin´s author.
Some plugin authors choose do not include "settings" .
If you have updated the plugin it might be that the new version does not include that ??
Does the plugin itself work ?
Is it the exact same version as on the other sites ?
As for the "edit" link - it can also be set to not appear or be disabled by third-party plugins that has to do with user-permissions or visibility of links (like adminimize for example)
example how to disable those links for plugin authors :
add_filter( 'plugin_action_links', 'disable_plugin_footlinks', 10, 4 );
function disable_plugin_footlinks( $actions, $plugin_file, $plugin_data, $context ) {
// Remove edit link. if you want to remove selective use if statement
if ( array_key_exists( 'edit', $actions ) )
unset( $actions['edit'] );
// Selectively remove deactivate link for specific plugins with if statement
if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
'plugin1_specific_name_folder_/plugin1_name.php',
'plugin2_name_folder_/plugin2_name.php'
)))
unset( $actions['deactivate'] );
return $actions;
}

Resources