classification = $classification; } public function register_hooks() { add_action( 'admin_menu', array( $this, 'add_menu' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_action( 'save_post', array( $this, 'save_meta_box' ) ); add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields' ), 10, 2 ); add_filter( 'attachment_fields_to_save', array( $this, 'save_attachment_fields' ), 10, 2 ); add_action( 'admin_post_aiparently_bulk_update', array( $this, 'handle_bulk_update' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); add_filter( 'plugin_action_links_' . plugin_basename( AIPARENTLY_FILE ), array( $this, 'action_links' ) ); } public function add_menu() { add_menu_page( __( 'AIparently', 'aiparently' ), __( 'AIparently', 'aiparently' ), 'edit_posts', 'aiparently', array( $this, 'render_dashboard' ), 'dashicons-visibility', 58 ); add_submenu_page( 'aiparently', __( 'Settings', 'aiparently' ), __( 'Settings', 'aiparently' ), 'manage_options', 'aiparently-settings', array( $this, 'render_settings' ) ); } public function register_settings() { register_setting( 'aiparently', 'aiparently_settings', array( 'sanitize_callback' => array( $this, 'sanitize_settings' ) ) ); } public function sanitize_settings( $input ) { $input = is_array( $input ) ? $input : array(); $position = isset( $input['position'] ) ? sanitize_key( $input['position'] ) : ''; $style = isset( $input['style'] ) ? sanitize_key( $input['style'] ) : ''; $image_label_position = isset( $input['image_label_position'] ) ? sanitize_key( $input['image_label_position'] ) : ''; return array( 'enabled' => empty( $input['enabled'] ) ? 0 : 1, 'position' => in_array( $position, array( 'before', 'after' ), true ) ? $position : 'after', 'style' => in_array( $style, array( 'badge', 'text' ), true ) ? $style : 'badge', 'images_enabled' => empty( $input['images_enabled'] ) ? 0 : 1, 'image_label_position' => in_array( $image_label_position, array( 'left', 'center', 'right' ), true ) ? $image_label_position : 'right', ); } public function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Overview', 'aiparently' ) . '' ); return $links; } public function enqueue_assets( $hook ) { if ( in_array( $hook, array( 'post.php', 'post-new.php', 'upload.php', 'media.php', 'toplevel_page_aiparently', 'aiparently_page_aiparently-settings' ), true ) ) { wp_enqueue_style( 'aiparently-admin', AIPARENTLY_URL . 'assets/css/admin.css', array(), AIPARENTLY_VERSION ); wp_enqueue_script( 'aiparently-admin', AIPARENTLY_URL . 'assets/js/admin.js', array(), AIPARENTLY_VERSION, true ); } } public function add_meta_boxes() { foreach ( array( 'post', 'page' ) as $post_type ) { add_meta_box( 'aiparently-classification', __( 'AIparently', 'aiparently' ), array( $this, 'render_meta_box' ), $post_type, 'side', 'default' ); } } public function render_meta_box( $post ) { wp_nonce_field( 'aiparently_save_classification', 'aiparently_nonce' ); $this->render_classification_fields( $this->classification->get_status( $post->ID ), 'aiparently' ); } private function render_classification_fields( $status, $prefix ) { $used = in_array( $status, array( 'assisted', 'generated' ), true ); if ( 'unchecked' === $status ) { echo '
' . esc_html__( 'Not reviewed yet. Saving will store “No” unless you change the selection.', 'aiparently' ) . '
'; } ?> classification->set_status( $post_id, $status ); } public function attachment_fields( $fields, $post ) { $status = $this->classification->get_status( $post->ID ); $used = in_array( $status, array( 'assisted', 'generated' ), true ); $html = ''; $html .= ' '; $html .= ''; $html .= '