Wordpress - Snippets: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
 
Zeile 1: Zeile 1:
 
== Absender E-Mail anpassen ==
 
== Absender E-Mail anpassen ==
 +
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail_from_name
 +
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail_from
 +
 
Die Mail-Adresse kann man in den Einstellungen zwar anpassen, aber bei manchen Tools wird trotzdem wordpress@... und als Absender Wordpress gesendet. Das ist manchmal unpraktisch. Z.B. wenn man mehrere Instanzen zu verwalten hat. So kann man es ändern.
 
Die Mail-Adresse kann man in den Einstellungen zwar anpassen, aber bei manchen Tools wird trotzdem wordpress@... und als Absender Wordpress gesendet. Das ist manchmal unpraktisch. Z.B. wenn man mehrere Instanzen zu verwalten hat. So kann man es ändern.
  
Den Absendernamen fuer die automatischen eMails anpassen
+
'''Den Absendernamen für die automatischen E-Mails anpassen'''
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
function tmdn_newMailFromName($old) {
+
add_filter( 'wp_mail_from_name', 'custom_wp_mail_from_name' );
  $senderName = 'Der Magical Digital Nomad Blog';
+
function custom_wp_mail_from_name( $original_email_from ) {
  return $senderName;
+
return 'WordPress Email System';
 
}
 
}
add_filter('wp_mail_from_name', 'tmdn_newMailFromName');
+
 
 +
//It is not necessary to call another method if you can use anonymous functions (PHP 5.3.0+):
 +
 
 +
add_filter( 'wp_mail_from_name', function( $name ) {
 +
return 'WordPress Email System';
 +
});
 +
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Die Sende-eMail-Adresse fuer die automatischen eMails anpassen
+
'''Sende E-Mail Adresse anpassen:'''
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
  
function tmdn_newMailFromAddr($old) {
+
add_filter( 'wp_mail_from', 'custom_wp_mail_from' );
  $sendEmail = 'office@the-magical-digital-nomad.com';
+
function custom_wp_mail_from( $original_email_address ) {
  return $sendEmail;
+
//Make sure the email is from the same domain
 +
//as your website to avoid being marked as spam.
 +
return 'webmaster@mydomainname.com';
 
}
 
}
add_filter('wp_mail_from', 'tmdn_newMailFromAddr');
+
 
 +
//It is not necessary to call another method if you can use anonymous functions (PHP 5.3.0+):
 +
 
 +
add_filter( 'wp_mail_from', function( $email ) {
 +
return 'webmaster@mydomainname.com';
 +
});
  
 
</syntaxhighlight>
 
</syntaxhighlight>

Aktuelle Version vom 16. Mai 2019, 13:50 Uhr

Absender E-Mail anpassen[Bearbeiten]

https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail_from_name
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail_from

Die Mail-Adresse kann man in den Einstellungen zwar anpassen, aber bei manchen Tools wird trotzdem wordpress@... und als Absender Wordpress gesendet. Das ist manchmal unpraktisch. Z.B. wenn man mehrere Instanzen zu verwalten hat. So kann man es ändern.

Den Absendernamen für die automatischen E-Mails anpassen

add_filter( 'wp_mail_from_name', 'custom_wp_mail_from_name' );
function custom_wp_mail_from_name( $original_email_from ) {
	return 'WordPress Email System';
}

//It is not necessary to call another method if you can use anonymous functions (PHP 5.3.0+):

add_filter( 'wp_mail_from_name', function( $name ) {
	return 'WordPress Email System';
});

Sende E-Mail Adresse anpassen:

add_filter( 'wp_mail_from', 'custom_wp_mail_from' );
function custom_wp_mail_from( $original_email_address ) {
	//Make sure the email is from the same domain 
	//as your website to avoid being marked as spam.
	return 'webmaster@mydomainname.com';
}

//It is not necessary to call another method if you can use anonymous functions (PHP 5.3.0+):

add_filter( 'wp_mail_from', function( $email ) {
	return 'webmaster@mydomainname.com';
});

Nach Login auf Homepage weiterleiten[Bearbeiten]

Es gibt ein paar Plugins dazu. Prinzipiell kann man einfach eine action ins Theme nehmen.

In die function.php des Themes einfügen (z.b. einfach ganz oben nach dem <?php ):

/* redirect users to front page after login */
function redirect_to_front_page() {
	global $redirect_to;
	if (!isset($_GET['redirect_to'])) {
		$redirect_to = get_option('siteurl');
	}
}
add_action('login_form', 'redirect_to_front_page');

Taxonomien im Backend nutzen[Bearbeiten]

Wordpress Plugina - Taxonomien nutzen

Admin User über FTP erzeugen[Bearbeiten]

Dieses Snippet anpassen, in die functions.php des Themes kopieren und Seite aufrufen. Nicht vergessen wieder entfernen.

function add_admin_acct(){
	$login = 'benutzername';
	$passw = 'meinpasswort';
	$email = 'schlegel@geo-bit.de';

	if ( !username_exists( $login )  && !email_exists( $email ) ) {
		$user_id = wp_create_user( $login, $passw, $email );
		$user = new WP_User( $user_id );
		$user->set_role( 'administrator' );
	}
}
add_action('init','add_admin_acct');