使用Redux更新wordpress博客名称和博客描述


Update wordpress blogname and blogdescription using Redux

是否可以通过Redux框架更新wordpress博客名称和博客描述。

array(
    'id'        => 'blogdescription',
    'type'      => 'text',
    'title'     => 'Blog Description',
    'default'   => '',
),

您可以使用update_option();功能

update_option( 'blogname', 'New Value' );

update_option( 'blogdescription', 'New Value' );

挂接管理员

add_action('admin_init', 'update_my_site_blog_info');
function update_my_site_blog_info() {
    $old  = get_option('blogdescription');
    $new = 'New Site Title';
    if ( $old  !== $new ) {
        update_option( 'blogdescription', $new  );
    }
}

编辑:

我想这样更好,

add_filter('redux/options/[your_opt_name]/compiler', 'update_my_site_blog_info');
function update_my_site_blog_info() {
    $new = 'New Site Title';
    update_option( 'blogdescription', $new  );
}

那么您的字段需要启用编译器

array(
    'id'        => 'blogdescription',
    'type'      => 'text',
    'title'     => 'Blog Description',
    'default'   => '',
    'compiler'  => true,
),

感谢您的帮助,我喜欢这样做是为了让它发挥作用。

add_action('init', 'update_my_site_blog_info');
    function update_my_site_blog_info()
    {
        global $opt_keyname;
        $check = array('blogdescription', 'blogname');
        foreach($check as $key)
        {
            if ( get_option($key)  != $opt_keyname[$key] )
            {
                update_option( $key, $opt_keyname[$key] );
            }
        }
    }

Redux::setSection( $opt_name,
        array(
            'title'     => 'Basic Settings',
            'id'        => 'basic_settings',
            'fields'    => array(
                array(
                    'id'        => 'blogname',
                    'type'      => 'text',
                    'title'     => 'Blog Title',
                    'default'   => get_option( 'blogname' )
                ),
                array(
                    'id'        => 'blogdescription',
                    'type'      => 'text',
                    'title'     => 'Blog Description',
                    'default'   => get_option( 'blogdescription' )
                ),
            )
        )
    );