This commit is contained in:
Javier Casares 2026-03-28 07:59:52 +00:00
commit ddaaff71ad
23 changed files with 879 additions and 798 deletions

View file

@ -54,6 +54,24 @@ class Robotstxt_OG_Admin_Settings {
add_action( 'admin_init', array( $this, 'handle_resolve_all' ) );
add_action( 'admin_init', array( $this, 'handle_clear_single' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
// Allow editors (edit_others_posts) to save settings via the Settings API.
// options.php defaults to manage_options; this filter lowers it for our group.
add_filter( 'option_page_capability_robotstxt_og_settings', array( $this, 'get_settings_capability' ) );
}
/**
* Return the capability required to save plugin settings.
*
* Allows users with edit_others_posts (editors and above) to save plugin
* settings through the WordPress Settings API (options.php).
*
* @since 1.0.3
*
* @return string Capability slug.
*/
public function get_settings_capability(): string {
return 'edit_others_posts';
}
/**
@ -77,7 +95,7 @@ class Robotstxt_OG_Admin_Settings {
}
// Verify nonce.
$nonce_raw = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_SPECIAL_CHARS );
$nonce_raw = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$nonce = $nonce_raw ? sanitize_text_field( wp_unslash( $nonce_raw ) ) : '';
if ( ! wp_verify_nonce( $nonce, 'robotstxt_og_clear_single_' . $post_id ) ) {
@ -85,7 +103,7 @@ class Robotstxt_OG_Admin_Settings {
}
// Check permissions.
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'robotstxt-og' ) );
}
@ -120,7 +138,7 @@ class Robotstxt_OG_Admin_Settings {
add_options_page(
__( 'OpenGraph Settings', 'robotstxt-og' ),
__( 'OpenGraph', 'robotstxt-og' ),
'manage_options',
'edit_others_posts',
'robotstxt-og-settings',
array( $this, 'render_settings_page' )
);
@ -344,7 +362,8 @@ class Robotstxt_OG_Admin_Settings {
* @return void
*/
public function render_fallback_image_field(): void {
$image_url = (string) get_option( 'robotstxt_og_fallback_image', '' );
$option_value = get_option( 'robotstxt_og_fallback_image', '' );
$image_url = is_string( $option_value ) ? $option_value : '';
?>
<input
type="url"
@ -368,7 +387,8 @@ class Robotstxt_OG_Admin_Settings {
* @return void
*/
public function render_homepage_image_field(): void {
$image_url = (string) get_option( 'robotstxt_og_homepage_image', '' );
$option_value = get_option( 'robotstxt_og_homepage_image', '' );
$image_url = is_string( $option_value ) ? $option_value : '';
?>
<input
type="url"
@ -492,7 +512,8 @@ class Robotstxt_OG_Admin_Settings {
* @return void
*/
public function render_twitter_site_field(): void {
$handle = (string) get_option( 'robotstxt_og_twitter_site', '' );
$option_value = get_option( 'robotstxt_og_twitter_site', '' );
$handle = is_string( $option_value ) ? $option_value : '';
?>
<input
type="text"
@ -517,7 +538,7 @@ class Robotstxt_OG_Admin_Settings {
*/
public function render_settings_page(): void {
// Check user capabilities.
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'robotstxt-og' ) );
}
@ -534,13 +555,13 @@ class Robotstxt_OG_Admin_Settings {
*/
public function handle_clear_cache(): void {
// Check if this is a cache clear request.
$clear_cache = filter_input( INPUT_GET, 'robotstxt_og_clear_cache', FILTER_SANITIZE_SPECIAL_CHARS );
$clear_cache = filter_input( INPUT_GET, 'robotstxt_og_clear_cache', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
if ( null === $clear_cache ) {
return;
}
// Verify nonce.
$nonce_raw = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_SPECIAL_CHARS );
$nonce_raw = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$nonce = $nonce_raw ? sanitize_text_field( wp_unslash( $nonce_raw ) ) : '';
if ( ! wp_verify_nonce( $nonce, 'robotstxt_og_clear_cache' ) ) {
@ -548,7 +569,7 @@ class Robotstxt_OG_Admin_Settings {
}
// Check permissions.
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'robotstxt-og' ) );
}
@ -581,13 +602,13 @@ class Robotstxt_OG_Admin_Settings {
*/
public function handle_resolve_all(): void {
// Check if this is a resolve all request.
$resolve_all = filter_input( INPUT_GET, 'robotstxt_og_resolve_all', FILTER_SANITIZE_SPECIAL_CHARS );
$resolve_all = filter_input( INPUT_GET, 'robotstxt_og_resolve_all', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
if ( null === $resolve_all ) {
return;
}
// Verify nonce.
$nonce_raw = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_SPECIAL_CHARS );
$nonce_raw = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$nonce = $nonce_raw ? sanitize_text_field( wp_unslash( $nonce_raw ) ) : '';
if ( ! wp_verify_nonce( $nonce, 'robotstxt_og_resolve_all' ) ) {
@ -595,7 +616,7 @@ class Robotstxt_OG_Admin_Settings {
}
// Check permissions.
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'robotstxt-og' ) );
}