PluginProbe
ActivityPub / 0.14.1
ActivityPub v0.14.1
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / class-admin.php

class-admin.php in ActivityPub 0.14.1, at includes/class-admin.php

167 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Activitypub;
3
4 /**
5 * ActivityPub Admin Class
6 *
7 * @author Matthias Pfefferle
8 */
9 class Admin {
10 /**
11 * Initialize the class, registering WordPress hooks
12 */
13 public static function init() {
14 \add_action( 'admin_menu', array( '\Activitypub\Admin', 'admin_menu' ) );
15 \add_action( 'admin_init', array( '\Activitypub\Admin', 'register_settings' ) );
16 \add_action( 'show_user_profile', array( '\Activitypub\Admin', 'add_fediverse_profile' ) );
17 \add_action( 'admin_enqueue_scripts', array( '\Activitypub\Admin', 'enqueue_scripts' ) );
18 }
19
20 /**
21 * Add admin menu entry
22 */
23 public static function admin_menu() {
24 $settings_page = \add_options_page(
25 'Welcome',
26 'ActivityPub',
27 'manage_options',
28 'activitypub',
29 array( '\Activitypub\Admin', 'settings_page' )
30 );
31
32 \add_action( 'load-' . $settings_page, array( '\Activitypub\Admin', 'add_settings_help_tab' ) );
33
34 $followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers (Fediverse)', 'activitypub' ), 'read', 'activitypub-followers-list', array( '\Activitypub\Admin', 'followers_list_page' ) );
35
36 \add_action( 'load-' . $followers_list_page, array( '\Activitypub\Admin', 'add_followers_list_help_tab' ) );
37 }
38
39 /**
40 * Load settings page
41 */
42 public static function settings_page() {
43 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
44 if ( empty( $_GET['tab'] ) ) {
45 $tab = 'welcome';
46 } else {
47 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
48 $tab = sanitize_key( $_GET['tab'] );
49 }
50
51 switch ( $tab ) {
52 case 'settings':
53 \load_template( \dirname( __FILE__ ) . '/../templates/settings.php' );
54 break;
55 case 'welcome':
56 default:
57 wp_enqueue_script( 'plugin-install' );
58 add_thickbox();
59 wp_enqueue_script( 'updates' );
60
61 \load_template( \dirname( __FILE__ ) . '/../templates/welcome.php' );
62 break;
63 }
64 }
65
66 /**
67 * Load user settings page
68 */
69 public static function followers_list_page() {
70 \load_template( \dirname( __FILE__ ) . '/../templates/followers-list.php' );
71 }
72
73 /**
74 * Register ActivityPub settings
75 */
76 public static function register_settings() {
77 \register_setting(
78 'activitypub',
79 'activitypub_post_content_type',
80 array(
81 'type' => 'string',
82 'description' => \__( 'Use title and link, summary, full or custom content', 'activitypub' ),
83 'show_in_rest' => array(
84 'schema' => array(
85 'enum' => array( 'title', 'excerpt', 'content' ),
86 ),
87 ),
88 'default' => 'content',
89 )
90 );
91 \register_setting(
92 'activitypub',
93 'activitypub_custom_post_content',
94 array(
95 'type' => 'string',
96 'description' => \__( 'Define your own custom post template', 'activitypub' ),
97 'show_in_rest' => true,
98 'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT,
99 )
100 );
101 \register_setting(
102 'activitypub',
103 'activitypub_object_type',
104 array(
105 'type' => 'string',
106 'description' => \__( 'The Activity-Object-Type', 'activitypub' ),
107 'show_in_rest' => array(
108 'schema' => array(
109 'enum' => array( 'note', 'article', 'wordpress-post-format' ),
110 ),
111 ),
112 'default' => 'note',
113 )
114 );
115 \register_setting(
116 'activitypub',
117 'activitypub_use_hashtags',
118 array(
119 'type' => 'boolean',
120 'description' => \__( 'Add hashtags in the content as native tags and replace the #tag with the tag-link', 'activitypub' ),
121 'default' => 0,
122 )
123 );
124 \register_setting(
125 'activitypub',
126 'activitypub_allowed_html',
127 array(
128 'type' => 'string',
129 'description' => \__( 'List of HTML elements that are allowed in activities.', 'activitypub' ),
130 'default' => ACTIVITYPUB_ALLOWED_HTML,
131 )
132 );
133 \register_setting(
134 'activitypub',
135 'activitypub_support_post_types',
136 array(
137 'type' => 'string',
138 'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ),
139 'show_in_rest' => true,
140 'default' => array( 'post', 'pages' ),
141 )
142 );
143 }
144
145 public static function add_settings_help_tab() {
146 require_once \dirname( __FILE__ ) . '/help.php';
147 }
148
149 public static function add_followers_list_help_tab() {
150 // todo
151 }
152
153 public static function add_fediverse_profile( $user ) {
154 ?>
155 <h2 id="activitypub"><?php \esc_html_e( 'ActivityPub', 'activitypub' ); ?></h2>
156 <?php
157 \Activitypub\get_identifier_settings( $user->ID );
158 }
159
160 public static function enqueue_scripts( $hook_suffix ) {
161 if ( false !== strpos( $hook_suffix, 'activitypub' ) ) {
162 wp_enqueue_style( 'activitypub-admin-styles', plugins_url( 'assets/css/activitypub-admin.css', ACTIVITYPUB_PLUGIN_FILE ), array(), '1.0.0' );
163 wp_enqueue_script( 'activitypub-admin-styles', plugins_url( 'assets/js/activitypub-admin.js', ACTIVITYPUB_PLUGIN_FILE ), array( 'jquery' ), '1.0.0', false );
164 }
165 }
166 }
167