allcaps ), 'ACTIVATION' ); } } ); /** * The core plugin class that is used to define internationalization, * admin-specific hooks, and public-facing site hooks. */ require plugin_dir_path( __FILE__ ) . 'includes/class-all-sources-images.php'; /** * WordPress Abilities API integration (WP 6.9+) * Must be loaded early to catch the wp_abilities_api_init hook. */ require plugin_dir_path( __FILE__ ) . 'includes/class-allsi-abilities.php'; /** * Add capabilities */ function ALLSI_add_capability() { // Don't log on every request // ALLSI_log_entry( 'ALLSI_add_capability' ); $options = get_option( 'ALLSI_plugin_rights_settings' ); // Administrators always have the capability $admin_role = get_role( 'administrator' ); if ( $admin_role ) { $admin_role->add_cap( 'ALLSI_manage', true ); } // Manage other roles by adding or removing capabilities according to options $roles = array( 'editor' => 'rights_editor', 'author' => 'rights_author', 'contributor' => 'rights_contributor', 'subscriber' => 'rights_subscriber', ); foreach ( $roles as $role_name => $option_key ) { $role = get_role( $role_name ); if ( $role ) { if ( isset( $options[$option_key] ) && $options[$option_key] === 'true' ) { // Adds capacity if the option is enabled $role->add_cap( 'ALLSI_manage', true ); } else { // Removes the capacity if the option is deactivated $role->remove_cap( 'ALLSI_manage' ); } } } } /** * Check hook wp_insert_post to fire functionalities * * @since 6.0.0 */ function ALLSI_check_hook() { } /** * Check capabilities before launching the plugin main features * * @since 5.0.0 */ function ALLSI_check_capability() { // Don't log on every request to avoid flooding the log // ALLSI_log_entry( 'ALLSI_check_capability' ); $additional_check = false; // add capability for the cron if ( wp_doing_cron() || true == $additional_check ) { global $current_user; $current_user->add_cap( 'ALLSI_manage' ); ALLSI_log( 'Added ALLSI_manage capability for cron', 'CAPABILITY' ); } // CRITICAL: Always allow administrators, even if ALLSI_manage capability not assigned // This prevents blocking the entire WordPress admin if ( ! current_user_can( 'manage_options' ) && ! current_user_can( 'ALLSI_manage' ) ) { // User doesn't have permission - just don't load plugin features // DON'T block WordPress or show errors return; } // User has permission - initialize plugin try { $plugin = new All_Sources_Images(); $plugin->run(); } catch ( Exception $e ) { ALLSI_log_error( 'Failed to initialize plugin', $e ); } } /** * Begins execution of the plugin. * * Since everything within the plugin is registered via hooks, * then kicking off the plugin from this point in the file does * not affect the page life cycle. * * @since 4.0.0 */ function ALLSI_run_plugin() { // User role & capacity add_action( 'init', 'ALLSI_add_capability', 1 ); add_action( 'init', 'ALLSI_check_capability', 2 ); // Features with hooks add_action( 'init', 'ALLSI_check_hook', 5 ); } ALLSI_run_plugin(); /** * Load New Admin UI * * @since 6.2.0 */ require_once plugin_dir_path( __FILE__ ) . 'admin/partials/new-ui/new-ui-loader.php';