post_type; } /** * Whether the caller may change Additional CSS, asked as WordPress asks. * * @param Request_Context $context Context. */ public static function can_edit( Request_Context $context ): bool { return $context->user_can( 'edit_css' ); } /** * Whether the caller may change a post: edit_css for Additional CSS, * edit_post for anything else. * * @param Request_Context $context Context. * @param \WP_Post $post Post. */ public static function can_change( Request_Context $context, \WP_Post $post ): bool { return self::is_css( $post ) ? self::can_edit( $context ) : $context->user_can( 'edit_post', (int) $post->ID ); } /** * The refusal for a caller who may not change Additional CSS. */ public static function forbidden(): string { return __( 'Changing a theme\'s Additional CSS needs the edit_css capability, which WordPress gives to administrators who may post unfiltered HTML (on multisite, only super admins).', 'gripmcp' ); } /** * Whether the tools may change CSS that is printed on the site: a theme's * Additional CSS, the custom CSS in its global styles, and Elementor's * custom CSS settings. The plugin from WordPress.org never does, since it * has no Paid_Writes; the paid version does on the plans that include it. */ public static function writable(): bool { return class_exists( Paid_Writes::class ) && Paid_Writes::css(); } /** * The refusal while writable() says no. */ public static function read_only(): string { return self::with_plan_note( __( 'Not changed: GripMCP reads the CSS that is printed on the site (a theme\'s Additional CSS, the custom CSS in its global styles, and Elementor\'s custom CSS settings) but does not change it. Change that CSS in wp-admin, under Appearance or in Elementor\'s editor.', 'gripmcp' ) ); } /** * A refusal while writable() says no, followed by the paid version's note * on the plans that change CSS. The plugin from WordPress.org adds none. * * @param string $text Refusal. */ public static function with_plan_note( string $text ): string { return class_exists( Paid_Writes::class ) ? $text . ' ' . Paid_Writes::css_plan_note() : $text; } /** * Why some CSS cannot be saved, or null. The same rule as the * Customizer: markup in a stylesheet is refused. * * @param string $css CSS. */ public static function markup_error( string $css ): ?string { if ( ! preg_match( '#) and send only the CSS rules.', 'gripmcp' ); } /** * Create a theme's Additional CSS, where writable() allows it. * * @param string $css CSS. * @param string $stylesheet Theme directory name. * @return \WP_Post|\WP_Error */ public static function create( string $css, string $stylesheet ) { if ( ! self::writable() ) { return new \WP_Error( 'gripmcp_css_read_only', self::read_only() ); } return Paid_Writes::create_css( $css, $stylesheet ); } /** * After a CSS post was saved, where writable() allows it: what WordPress * needed to serve it and which caches were purged. * * @param \WP_Post $post Saved post. * @return array{notes:array, refreshed:array, summary:string} */ public static function after_save( \WP_Post $post ): array { if ( ! self::writable() ) { return array( 'notes' => array(), 'refreshed' => array(), 'summary' => '', ); } return Paid_Writes::after_css_save( $post ); } }