plugin_file = $plugin_file; } /** * Haakt aan. */ public function register(): void { add_action( 'admin_init', array( $this, 'register_setting' ) ); if ( '' !== $this->plugin_file ) { add_filter( 'plugin_action_links_' . plugin_basename( $this->plugin_file ), array( $this, 'action_links' ) ); } } /** * Meldt de optie, de sectie en het veld aan. */ public function register_setting(): void { register_setting( 'media', ApplyPolicy::OPTION, array( 'type' => 'string', 'sanitize_callback' => array( $this, 'sanitize' ), 'default' => ApplyPolicy::MODE_AUTO, 'show_in_rest' => false, ) ); // `before_section`/`after_section` bestaan sinds WordPress 6.1 en zijn // hier de enige manier om een anker te krijgen: do_settings_sections() // schrijft de

zonder id, dus zonder dit wijst de "Instellingen"-link // vanaf de pluginlijst naar het begin van de pagina. add_settings_section( 'yinga_focus', Naming::product(), array( $this, 'section' ), 'media', array( 'before_section' => '
', 'after_section' => '
', ) ); add_settings_field( ApplyPolicy::OPTION, __( 'Apply on the front end', 'yinga-focus' ), array( $this, 'field' ), 'media', 'yinga_focus', array( 'label_for' => ApplyPolicy::OPTION . '_' . ApplyPolicy::MODE_AUTO ) ); } /** * Alleen de drie bekende standen komen erdoor. Al het andere valt terug op * de standaard; een onbekende waarde mag nooit tot een ongedefinieerde * toestand leiden. * * @param mixed $value De ingezonden waarde. * @return string */ public function sanitize( $value ): string { $value = is_string( $value ) ? sanitize_key( $value ) : ''; return in_array( $value, ApplyPolicy::modes(), true ) ? $value : ApplyPolicy::MODE_AUTO; } /** * De uitleg boven het veld. */ public function section(): void { echo '

'; echo esc_html__( 'Yinga Focus can apply the focal point to your images automatically. It does that with object-position, which only affects images your theme already crops — an image that is fully visible now does not change.', 'yinga-focus' ); echo '

'; } /** * De drie radioknoppen. */ public function field(): void { $current = get_option( ApplyPolicy::OPTION, ApplyPolicy::MODE_AUTO ); if ( ! in_array( $current, ApplyPolicy::modes(), true ) ) { $current = ApplyPolicy::MODE_AUTO; } $options = array( ApplyPolicy::MODE_AUTO => array( __( 'Automatic', 'yinga-focus' ), __( 'Recommended. Every image with a focal point gets it applied.', 'yinga-focus' ), ), ApplyPolicy::MODE_PROPERTY => array( __( 'Make available only', 'yinga-focus' ), __( 'The plugin only sets the CSS variable --yf-pos. Your theme decides what to do with it.', 'yinga-focus' ), ), ApplyPolicy::MODE_OFF => array( __( 'Off', 'yinga-focus' ), __( 'The plugin leaves the front end alone. The focal data is kept and stays usable through the API.', 'yinga-focus' ), ), ); echo '
'; printf( '%s', esc_html__( 'Apply on the front end', 'yinga-focus' ) ); foreach ( $options as $value => $labels ) { printf( '', esc_attr( ApplyPolicy::OPTION . '_' . $value ), esc_attr( ApplyPolicy::OPTION ), esc_attr( $value ), checked( $current, $value, false ), esc_html( $labels[0] ), esc_html( $labels[1] ) ); } echo '
'; } /** * Een link naar de instelling vanaf de pluginlijst. * * @param mixed $links De bestaande links. * @return mixed */ public function action_links( $links ) { if ( ! is_array( $links ) ) { return $links; } array_unshift( $links, sprintf( '%s', esc_url( admin_url( 'options-media.php#yinga_focus' ) ), esc_html__( 'Settings', 'yinga-focus' ) ) ); return $links; } }