*/ class Disable_Wp_Notification_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; } /** * Register the menu for the admin area. * * @since 1.0.0 */ public function admin_menu() { /** * An instance of this class should be passed to the run() function * defined in Disable_Wp_Notification_Loader as all of the hooks are defined * in that particular class. * * The Disable_Wp_Notification_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ /* * Check if this setting can be managed by only the site administrator * No other user role will be able to manage this settings */ if(function_exists('wp_get_current_user')){ $user = wp_get_current_user(); $CurentUserRoles = (array) $user->roles; if(in_array('administrator', $CurentUserRoles)){ add_menu_page( __('Disable Notifications', 'disable-wp-notification'), __('Disable Notices', 'disable-wp-notification'), 'manage_options', 'disable-wp-notification', array($this, 'disable_notification'), 'dashicons-welcome-comments', 99 ); } } } /** * Options page callback * * @since 3.2 */ public function disable_notification() { $option = array(); $option['enable'] = ''; $option['all'] = ''; $option['without-admin'] = ''; // Set class property if(isset($_POST['disable_notifications'])){ $user_role = sanitize_text_field($_POST['disable_notifications']['user_role']); $savedOptions['user_role'] = $user_role; update_option('disable_notifications', $savedOptions); } $options = get_option( 'disable_notifications' ); if (!empty($options)) { if (in_array('enable', $options)) { $option['enable'] = 'checked = "checked"'; } if (in_array('all', $options)) { $option['all'] = 'checked = "checked"'; } if (in_array('without-admin', $options)) { $option['without-admin'] = 'checked = "checked"'; } } ?>
plugin_name, plugin_dir_url( __FILE__ ) . 'css/disable-wp-notification-admin.css', array(), $this->version, 'all' ); if(isset($_POST['disable_notifications'])){ $user_role = sanitize_text_field($_POST['disable_notifications']['user_role']); $options['user_role'] = $user_role; } else { $options = get_option('disable_notifications'); } if(!empty($options) && function_exists('wp_get_current_user')){ $user = wp_get_current_user(); $CurentUserRoles = (array) $user->roles; if(in_array('enable', $options)){ } else { if ( (in_array('all', $options)) || (!in_array('administrator', $CurentUserRoles) && in_array('without-admin', $options)) ) { ?> plugin_name, plugin_dir_url( __FILE__ ) . 'js/disable-wp-notification-admin.js', array( 'jquery' ), $this->version, false ); if(isset($_POST['disable_notifications'])){ $user_role = sanitize_text_field($_POST['disable_notifications']['user_role']); $options['user_role'] = $user_role; } else { $options = get_option('disable_notifications'); } if(!empty($options) && function_exists('wp_get_current_user')){ $user = wp_get_current_user(); $CurentUserRoles = (array) $user->roles; if(in_array('enable', $options)){ } else { if ( (in_array('administrator', $CurentUserRoles) && in_array('all', $options)) || (!in_array('administrator', $CurentUserRoles) && in_array('without-admin', $options)) ) { wp_enqueue_script( $this->plugin_name.'-1', plugin_dir_url( __FILE__ ) . 'js/disable-wp-notifications.js', array( 'jquery' ), $this->version, false ); } } } } public function add_settings_link( $links ) { $settings_link = '' . __( 'Settings' ) . ''; array_push( $links, $settings_link ); return $links; } }