Implement site name and description settings

This commit is contained in:
Jeremy Dormitzer 2018-11-06 08:18:04 -05:00
parent 024c4809e2
commit bccd383de3
3 changed files with 54 additions and 4 deletions

View File

@ -2,10 +2,22 @@
namespace pterotype\settings;
function register_settings_sections() {
\register_setting( 'pterotype_settings', 'pterotype_blog_name', array(
'type' => 'string',
'description' => __( "The site's name in the Fediverse", 'pterotype' ),
'show_in_rest' => true,
) );
\register_setting( 'pterotype_settings', 'pterotype_blog_description', array(
'type' => 'string',
'description' => __( "The site's description in the Fediverse", 'pterotype' ),
'show_in_rest' => true,
) );
\add_settings_section(
'pterotype_identity',
'Fediverse Identity',
'',
function() {
?><p>These settings determine how your blog will look in other Fediverse apps</p><?php
},
'pterotype'
);
}
@ -17,11 +29,40 @@ function register_settings_fields() {
function() {
// TODO fill this with the existing option or the site default if not set
?>
<input type="text" name="pterotype_blog_name">
<input type="text"
name="pterotype_blog_name"
value="<?php echo get_blog_name_value(); ?>">
<?php
},
'pterotype',
'pterotype_identity'
);
\add_settings_field(
'pterotype_blog_description',
'Site Description',
function() {
?>
<textarea name="pterotype_blog_description"><?php echo get_blog_description_value(); ?></textarea>
<?php
},
'pterotype',
'pterotype_identity'
);
}
function get_blog_name_value() {
$name = \get_option( 'pterotype_blog_name' );
if ( $name && ! empty( $name ) ) {
return $name;
}
return \get_bloginfo( 'name' );
}
function get_blog_description_value() {
$description = \get_option( 'pterotype_blog_description' );
if ( $description && ! empty( $description ) ) {
return $description;
}
return \get_bloginfo( 'description' );
}
?>

View File

@ -81,6 +81,14 @@ add_action( "update_option_theme_mods_$theme", function() {
\pterotype\identity\update_identity( PTEROTYPE_BLOG_ACTOR_SLUG );
} );
add_action( 'update_option_pterotype_blog_name', function() {
\pterotype\identity\update_identity( PTEROTYPE_BLOG_ACTOR_SLUG );
} );
add_action( 'update_option_pterotype_blog_description', function() {
\pterotype\identity\update_identity( PTEROTYPE_BLOG_ACTOR_SLUG );
} );
add_action( 'admin_menu', function() {
\pterotype\admin\register_admin_page();
\pterotype\settings\register_settings_sections();

View File

@ -3,6 +3,7 @@ namespace pterotype\actors;
require_once plugin_dir_path( __FILE__ ) . '../pgp.php';
require_once plugin_dir_path( __FILE__ ) . 'objects.php';
require_once plugin_dir_path( __FILE__ ) . '../admin/settings.php';
function get_actor( $id ) {
global $wpdb;
@ -153,10 +154,10 @@ function get_blog_actor() {
'outbox' => get_rest_url(
null, sprintf( '/pterotype/v1/actor/%s/outbox', PTEROTYPE_BLOG_ACTOR_SLUG )
),
'name' => get_bloginfo( 'name' ),
'name' => \pterotype\settings\get_blog_name_value(),
// TODO in the future, make this configurable, both here and in the Webfinger handler
'preferredUsername' => PTEROTYPE_BLOG_ACTOR_USERNAME,
'summary' => get_bloginfo( 'description' ),
'summary' => \pterotype\settings\get_blog_description_value(),
'url' => network_site_url( '/' ),
'publicKey' => array(
'id' => get_rest_url(