J'essaie de mettre à jour un plugin appelé Theme My Login avec les paramètres par défaut. Le problème est que les mises à jour ne sont appliquées qu'à la base de données. Lorsque je me connecte à WordPress, les options ne sont pas mises à jour. Comme indiqué pour les valeurs par défaut, j’ai utilisé get_option avant update_option.
J'ai même fait la mise à jour du plugin lors de l'activation. J'ai eu la réponse d'une question similaire .
S'il vous plaît examiner les fonctions, je ne sais pas ce que je pourrais éventuellement faire mal ou manquant.
//Theme My Login Custom Settings
function nls_tml_default_activation_actions() {
do_action( 'nls_tml_default_activation' );
}
register_activation_hook( __FILE__, 'nls_tml_default_activation_actions');
add_action( 'nls_tml_default_activation', 'nls_tml_default_settings' );
function nls_tml_default_settings() {
get_option('theme_my_login');
update_option('theme_my_login', $nlstml);
$nlstml = array (
'option_value' => 'a:4:{s:10:"enable_css";b:1;s:10:"login_type";s:7:"default";s:14:"active_modules";a:6:{i:0;s:37:"custom-passwords/custom-passwords.php";i:1;s:39:"custom-user-links/custom-user-links.php";i:2;s:23:"recaptcha/recaptcha.php";i:3;s:21:"security/security.php";i:4;s:35:"themed-profiles/themed-profiles.php";i:5;s:35:"user-moderation/user-moderation.php";}s:7:"version";s:6:"6.4.10";}',
'autoload' => 'yes',
);
get_option('theme_my_login_recaptcha');
update_option('theme_my_login_recaptcha', $nlsrecap);
$nlsrecap = array (
'option_value' => 'a:3:{s:10:"public_key";s:7:"sitekey";s:11:"private_key";s:9:"secretkey";s:5:"theme";s:5:"light";}',
'autoload' => 'yes',
);
get_option('theme_my_login_security');
update_option('theme_my_login_security', $nlssecurity);
$nlssecurity = array (
'option_value' => 'a:3:{s:12:"private_site";b:0;s:13:"private_login";b:1;s:12:"failed_login";a:5:{s:9:"threshold";i:5;s:18:"threshold_duration";i:1;s:23:"threshold_duration_unit";s:4:"hour";s:16:"lockout_duration";i:24;s:21:"lockout_duration_unit";s:4:"hour";}}',
'autoload' => 'yes',
);
get_option('theme_my_login_themed_profiles');
update_option('theme_my_login_themed_profiles', $nlsprofiles);
$nlsprofiles = array (
'option_value' => 'a:7:{s:13:"administrator";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:0;}s:6:"editor";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}s:6:"author";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}s:11:"contributor";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}s:10:"subscriber";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}s:13:"wpseo_manager";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}s:12:"wpseo_editor";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}}',
'autoload' => 'yes',
);
get_option('theme_my_login_moderation');
update_option('theme_my_login_moderation', $nlsmoderation);
$nlsmoderation = array (
'option_value' => 'a:1:{s:4:"type";s:5:"admin";}',
'autoload' => 'yes',
);
}
Voici un autre exemple que j'ai créé sur la base d'une réponse similaire de @Otto:
//Theme My Login Custom Settings
function meks_wp_parse_args( &$a, $b ) {
$a = (array) $a;
$b = (array) $b;
$result = $b;
foreach ( $a as $k => &$v ) {
if ( is_array( $v ) && isset( $result[ $k ] ) ) {
$result[ $k ] = meks_wp_parse_args( $v, $result[ $k ] );
} else {
$result[ $k ] = $v;
}
}
return $result;
}
function nls_tml_default_activation_actions() {
do_action( 'nls_tml_default_activation' );
}
register_activation_hook( __FILE__, 'nls_tml_default_activation_actions');
add_action( 'nls_tml_default_activation', 'nls_tml_default_settings' );
function nls_tml_default_settings() {
$nls_tml_defaults = array(
'theme_my_login' => array(
'option_value' => 'a:4:{s:10:"enable_css";b:1;s:10:"login_type";s:7:"default";s:14:"active_modules";a:6:{i:0;s:37:"custom-passwords/custom-passwords.php";i:1;s:39:"custom-user-links/custom-user-links.php";i:2;s:23:"recaptcha/recaptcha.php";i:3;s:21:"security/security.php";i:4;s:35:"themed-profiles/themed-profiles.php";i:5;s:35:"user-moderation/user-moderation.php";}s:7:"version";s:6:"6.4.10";}',
'autoload' => 'yes',
),
'theme_my_login_recaptcha' => array(
'option_value' => 'a:3:{s:10:"public_key";s:7:"sitekey";s:11:"private_key";s:9:"secretkey";s:5:"theme";s:5:"light";}',
'autoload' => 'yes',
),
'theme_my_login_security' => array(
'option_value' => 'a:3:{s:12:"private_site";b:0;s:13:"private_login";b:1;s:12:"failed_login";a:5:{s:9:"threshold";i:5;s:18:"threshold_duration";i:1;s:23:"threshold_duration_unit";s:4:"hour";s:16:"lockout_duration";i:24;s:21:"lockout_duration_unit";s:4:"hour";}}',
'autoload' => 'yes',
),
'theme_my_login_themed_profiles' => array(
'option_value' => 'a:7:{s:13:"administrator";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:0;}s:6:"editor";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}s:6:"author";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}s:11:"contributor";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}s:10:"subscriber";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}s:13:"wpseo_manager";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}s:12:"wpseo_editor";a:2:{s:13:"theme_profile";b:1;s:14:"restrict_admin";b:1;}}',
'autoload' => 'yes',
),
'theme_my_login_moderation' => array(
'option_value' => 'a:1:{s:4:"type";s:5:"admin";}',
'autoload' => 'yes',
)
);
// Only variables are passed to the function by reference (Strict Standards warning)
$nls_options = get_option('plugin_options');
$nls_options = meks_wp_parse_args($nls_options, $nls_tml_defaults);
}
get_option () utilisé inutilement.
function nls_tml_default_settings() {
$nlstml = array(
'enable_css' => 1,
'login_type' => 'default',
'active_modules' => array(
'custom-passwords/custom-passwords.php',
'custom-user-links/custom-user-links.php',
'recaptcha/recaptcha.php',
'security/security.php',
'themed-profiles/themed-profiles.php',
'user-moderation/user-moderation.php',
),
'version' => '6.4.10',
);
update_option( 'theme_my_login', $nlstml );
$nlsrecap = array(
'public_key' => 'sitekey',
'private_key' => 'secretkey',
'theme' => 'light',
);
update_option( 'theme_my_login_recaptcha', $nlsrecap );
$nlssecurity = array(
'private_site' => '',
'private_login' => 1,
'failed_login' => array(
'threshold' => 5,
'threshold_duration' => 1,
'threshold_duration_unit' => 'hour',
'lockout_duration' => 24,
'lockout_duration_unit' => 'hour',
),
);
update_option( 'theme_my_login_security', $nlssecurity );
$nlsprofiles = array(
'administrator' => array(
'theme_profile' => 1,
'restrict_admin' => '',
),
'editor' => array(
'theme_profile' => 1,
'restrict_admin' => 1,
),
'author' => array(
'theme_profile' => 1,
'restrict_admin' => 1,
),
'contributor' => array(
'theme_profile' => 1,
'restrict_admin' => 1,
),
'subscriber' => array(
'theme_profile' => 1,
'restrict_admin' => 1,
),
'wpseo_manager' => array(
'theme_profile' => 1,
'restrict_admin' => 1,
),
'wpseo_editor' => array(
'theme_profile' => 1,
'restrict_admin' => 1,
),
);
update_option( 'theme_my_login_themed_profiles', $nlsprofiles );
$nlsmoderation = array(
'type' => 'admin',
);
update_option( 'theme_my_login_moderation', $nlsmoderation );
}
register_activation_hook (WP_PLUGIN_DIR. '/theme-my-login/theme-my-login.php', 'nls_tml_default_settings');