add_cap( 'akram_edit' ); } } $admin = get_role( 'administrator' ); if ( $admin ) { $admin->add_cap( 'akram_manage' ); } } public static function maybe_upgrade() { $ver = (int) get_option( 'akram_db_version', 0 ); if ( $ver < self::DB_VERSION ) { self::add_caps(); update_option( 'akram_db_version', self::DB_VERSION ); } if ( get_option( 'akram_version' ) !== AKRAM_VERSION ) { $previous = get_option( 'akram_version' ); update_option( 'akram_version', AKRAM_VERSION ); if ( $previous ) { // Render engine may have improved: stylesheets are rebuilt on the server in the background, // and the dashboard offers a one-click rebuild of the page markup. wp_schedule_single_event( time(), 'akram_rebuild_css' ); update_option( 'akram_needs_rebuild', 1 ); } } } /** Whether the current user may use the builder (role manager aware). */ public static function can_build( $post_id = 0 ) { if ( ! is_user_logged_in() ) { return false; } $ok = current_user_can( 'akram_edit' ) || current_user_can( 'manage_options' ); if ( ! $ok ) { $roles = (array) Options::get( 'roles', array() ); $user = wp_get_current_user(); $ok = (bool) array_intersect( $roles, (array) $user->roles ); } if ( $ok && $post_id ) { $ok = current_user_can( 'edit_post', $post_id ); } return (bool) apply_filters( 'akram_can_build', $ok, $post_id ); } /** Content-only editors can change text and media but not structure or styling. */ public static function content_only() { $roles = (array) Options::get( 'content_roles', array() ); if ( ! $roles || current_user_can( 'manage_options' ) ) { return false; } $user = wp_get_current_user(); return (bool) array_intersect( $roles, (array) $user->roles ); } public static function can_manage() { return current_user_can( 'akram_manage' ) || current_user_can( 'manage_options' ); } /** * ".min" when the minified builds are loaded, "" for the readable ones. * Every compiled file in assets/build/ ships twice: readable (popup.js) and minified (popup.min.js). * Sites load the minified copy; with SCRIPT_DEBUG on (or after `npm run watch`) the readable build is loaded. */ public static function min_suffix() { static $min = null; if ( null === $min ) { $debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; $min = $debug || ! file_exists( AKRAM_DIR . 'assets/build/editor.min.js' ) ? '' : '.min'; } return $min; } /** File name to load for a compiled file, e.g. "m/popup.js" → "m/popup.min.js". */ public static function build_file( $file ) { return preg_replace( '/\.(js|css)$/', self::min_suffix() . '.$1', $file ); } /** URL of a compiled file in assets/build/ (see min_suffix()). */ public static function build_url( $file ) { return AKRAM_URL . 'assets/build/' . self::build_file( $file ); } }