RequirementsManager.php 0000644 00000010541 15021307060 0011226 0 ustar 00 set_initial_groups();
}
/**
* @return RequirementsManager
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new RequirementsManager();
}
return self::$instance;
}
protected function set_initial_groups() {
// Requirements can be added with any group key desired but only registered groups will be displayed.
$this->groups = apply_filters(
'ngg_admin_requirements_manager_groups',
[
'phpext' => esc_html__( 'NextGen Gallery requires the following PHP extensions to function correctly. Please contact your hosting provider or systems admin and ask them for assistance:', 'nggallery' ),
'phpver' => esc_html__( 'NextGen Gallery has degraded functionality because of your PHP version. Please contact your hosting provider or systems admin and ask them for assistance:', 'nggallery' ),
'dirperms' => esc_html__( 'NextGen Gallery has found an issue trying to access the following files or directories. Please ensure the following locations have the correct permissions:', 'nggallery' ),
]
);
}
public static function register_requirements() {
$manager = self::get_instance();
$manager->add(
'nextgen_data_sanitation',
'phpext',
function () {
return class_exists( 'DOMDocument' );
},
[ 'message' => esc_html__( 'XML is strongly encouraged for safely editing image data', 'nggallery' ) ]
);
$manager->add(
'nextgen_data_gd_requirement',
'phpext',
function () {
return function_exists( 'gd_info' );
},
[
'message' => esc_html__( 'GD is required for generating image thumbnails, resizing images, and generating watermarks', 'nggallery' ),
'dismissable' => false,
]
);
$manager->add(
'nextgen_data_ctypes_requirement',
'phpext',
function () {
return function_exists( 'ctype_lower' );
},
[
'message' => esc_html__( 'ctype methods are required for securing user submitted data', 'nggallery' ),
'dismissable' => false,
]
);
}
/**
* @param string $name Unique notification ID
* @param string $group Choose one of phpext | phpver | dirperms
* @param callable $callback Method that determines whether the notification should display
* @param array $data Possible keys: className, message, dismissable
*/
public function add( $name, $group, $callback, $data ) {
$this->requirements[ $group ][ $name ] = new RequirementsNotice( $name, $callback, $data );
}
/**
* @param string $name
*/
public function remove( $name ) {
unset( $this->notifications[ $name ] );
}
public function create_notification() {
foreach ( $this->groups as $groupID => $groupLabel ) {
if ( empty( $this->requirements[ $groupID ] ) ) {
continue;
}
$dismissable = true;
$notices = [];
foreach ( $this->requirements[ $groupID ] as $key => $requirement ) {
$passOrFail = $requirement->run_callback();
if ( ! $passOrFail ) {
// If any of the notices can't be dismissed then all notices in that group can't be dismissed.
if ( ! $requirement->is_dismissable() ) {
// Add important notices to the beginning of the list.
$dismissable = false;
array_unshift( $notices, $requirement );
} else {
$notices[] = $requirement;
}
}
}
// Don't display empty group notices.
if ( empty( $notices ) ) {
continue;
}
// Generate the combined message for this group.
$message = '
is_recommended_plugin_installed( 'all-in-one-seo-pack' );
$installs_text = ! $is_installed ? esc_html__( 'Installs All In One SEO Pack', 'nextgen-gallery' ) : esc_html__( 'All In One SEO Pack is already installed', 'nextgen-gallery' );
?>
is_recommended_plugin_installed( 'wp-mail-smtp' );
$installs_text = ! $is_installed ? esc_html__( 'Installs WP Mail SMTP', 'nextgen-gallery' ) : esc_html__( 'WP Mail SMTP is already installed', 'nextgen-gallery' );
?>
Upgrade to PRO and Enter your license key below', 'nextgen-gallery' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_url( 'https://imagely.com/lite/?utm_source=liteplugin&utm_medium=wizard&utm_campaign=wizard' )
);
?>
ngg_condition_check_to_display_tooltip();
if ( ! $display_tooltip ) {
return;
}
?>
count();
// Check if there are any galleries.
if ( $gallery_count > 0 ) {
return false;
}
// Bail if user is on manage galleries screen.
$screen = get_current_screen();
if ( false !== strpos( $screen->id, 'ngg_addgallery' ) || false !== strpos( $screen->id, 'nggallery-manage-gallery' ) ) {
return false;
}
// Bail if the user is not allowed to save settings.
if ( ! current_user_can( 'manage_options' ) ) {
return false;
}
// Bail if the user has dismissed the tooltip within 7 days.
$show_tooltip = get_option( 'ngg_admin_menu_tooltip', 0 );
if ( $show_tooltip && ( $show_tooltip + 7 * DAY_IN_SECONDS > time() ) ) {
// Dismissed less than 7 days ago.
return false;
}
return true;
}
/**
* Store the time when the float bar was hidden so it won't show again for 14 days.
*/
public function mark_admin_menu_tooltip_hidden() {
check_ajax_referer( 'ngg-tooltip-admin-nonce', 'nonce' );
update_option( 'ngg_admin_menu_tooltip', time() );
wp_send_json_success();
}
}