'; printf( '

%s

', esc_html__( 'Hello', 'robotstxt-hello' ) ); if ( ! $this->is_manager_active() ) { $this->render_manager_message( false ); } $this->render_settings_form(); echo ''; } /** * Renders the plugin settings form. * * @since 1.2.4 * * @return void */ private function render_settings_form() { echo '
'; settings_fields( 'robotstxt-hello' ); printf( '

', checked( '1', get_option( self::OPTION_DELETE_DATA, '' ), false ), esc_html__( 'Delete plugin data on uninstall', 'robotstxt-hello' ) ); printf( '

%s

', esc_html__( 'All plugin data will be removed when the plugin is uninstalled.', 'robotstxt-hello' ) ); submit_button(); echo '
'; } /** * Renders the Manager (by ROBOTSTXT) notice on the plugins list page. * * The notice only appears on the plugins list page (single site or * network), only while the manager plugin is not active, and only * for users who have not dismissed it yet. * * @since 1.2.4 * * @return void */ public function render_manager_notice() { $screen = get_current_screen(); if ( ! $screen instanceof WP_Screen ) { return; } if ( ! in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ) { return; } if ( $this->is_manager_active() || $this->is_notice_dismissed() ) { return; } $this->render_manager_message( true ); } /** * Renders the shared Manager (by ROBOTSTXT) recommendation message. * * @since 1.2.4 * * @param bool $dismissible Whether the notice can be dismissed. * @return void */ private function render_manager_message( $dismissible ) { $classes = 'notice notice-warning robotstxt-hello-manager-notice'; if ( $dismissible ) { $classes .= ' is-dismissible'; } printf( '

%2$s %4$s

', esc_attr( $classes ), esc_html__( 'To receive automatic updates, the plugin Manager (by ROBOTSTXT) must be installed and active.', 'robotstxt-hello' ), esc_url( self::MANAGER_PLUGIN_URL ), esc_html__( 'Get Manager (by ROBOTSTXT)', 'robotstxt-hello' ) ); } /** * Enqueues the dismissal script on the plugins list page. * * @since 1.2.4 * * @param string $hook_suffix Current admin page hook suffix. * @return void */ public function enqueue_scripts( $hook_suffix ) { if ( 'plugins.php' !== $hook_suffix ) { return; } if ( $this->is_manager_active() || $this->is_notice_dismissed() ) { return; } wp_enqueue_script( 'robotstxt-hello-manager-notice', plugins_url( 'assets/js/manager-notice.js', ROBOTSTXT_HELLO_FILE ), array(), ROBOTSTXT_HELLO_VERSION, true ); wp_localize_script( 'robotstxt-hello-manager-notice', 'robotstxthellomanagernotice', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'robotstxt-hello-manager-notice' ), ) ); } /** * Persists the dismissal of the manager notice for the current user. * * @since 1.2.4 * * @return void */ public function handle_dismiss() { check_ajax_referer( 'robotstxt-hello-manager-notice', 'nonce' ); if ( ! current_user_can( 'activate_plugins' ) ) { wp_die( '', '', 403 ); } update_user_meta( get_current_user_id(), self::USER_META_DISMISSED, '1' ); wp_die( '', '', 200 ); } /** * Checks whether the Manager (by ROBOTSTXT) plugin is active. * * Detection covers both single-site and network-wide activation. * * @since 1.2.4 * * @return bool True when any active plugin basename starts with 'robotstxt-manager/'. */ private function is_manager_active() { $active = (array) get_option( 'active_plugins', array() ); if ( is_multisite() ) { $active = array_merge( $active, array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) ) ); } foreach ( $active as $basename ) { if ( is_string( $basename ) && 0 === strpos( $basename, 'robotstxt-manager/' ) ) { return true; } } return false; } /** * Checks whether the current user dismissed the manager notice. * * @since 1.2.4 * * @return bool True when the notice was dismissed by the current user. */ private function is_notice_dismissed() { return '1' === get_user_meta( get_current_user_id(), self::USER_META_DISMISSED, true ); } } }