current_page() ? $classes . ' tpg-admin' : $classes; } public function menu() { $icon = 'data:image/svg+xml;base64,' . base64_encode( '' ); add_menu_page( '3pika Gallery', '3pika Gallery', 'edit_posts', 'tpika-galleries', array( $this, 'page_list' ), $icon, 26 ); add_submenu_page( 'tpika-galleries', __( 'All Galleries', '3pika-gallery' ), __( 'All Galleries', '3pika-gallery' ), 'edit_posts', 'tpika-galleries', array( $this, 'page_list' ) ); add_submenu_page( 'tpika-galleries', __( 'Create New Gallery', '3pika-gallery' ), __( 'Create New Gallery', '3pika-gallery' ), 'edit_posts', 'tpika-new', array( $this, 'page_builder' ) ); add_submenu_page( 'tpika-galleries', __( 'Settings', '3pika-gallery' ), __( 'Settings', '3pika-gallery' ), 'manage_options', 'tpika-settings', array( $this, 'page_settings' ) ); $label = __( 'Go Premium', '3pika-gallery' ); add_submenu_page( 'tpika-galleries', __( 'Premium', '3pika-gallery' ), $label, 'manage_options', 'tpika-premium', array( $this, 'page_premium' ) ); } /** * Current admin page slug if it's ours. * * @return string */ private function current_page() { $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification return in_array( $page, self::PAGES, true ) ? $page : ''; } public function assets( $hook ) { $page = $this->current_page(); if ( ! $page ) { return; } $ver = TPIKA_VERSION . '.' . (int) @filemtime( TPIKA_PATH . 'assets/admin/admin.css' ); // cache-bust after every update wp_enqueue_style( 'tpika-admin', TPIKA_URL . 'assets/admin/admin.css', array(), $ver ); wp_enqueue_script( 'tpika-admin', TPIKA_URL . 'assets/admin/admin.js', array( 'jquery' ), TPIKA_VERSION . '.' . (int) @filemtime( TPIKA_PATH . 'assets/admin/admin.js' ), true ); wp_localize_script( 'tpika-admin', 'TPIKA_ADMIN', array( 'i18n' => array( 'copied' => __( 'Copied!', '3pika-gallery' ), 'confirmDelete' => __( 'Delete this gallery permanently? Images stay in the Media Library.', '3pika-gallery' ), 'confirmTitle' => __( 'Are you sure?', '3pika-gallery' ), 'cancel' => __( 'Cancel', '3pika-gallery' ), 'ok' => __( 'Confirm', '3pika-gallery' ), 'deleteBtn' => __( 'Delete', '3pika-gallery' ), 'noFile' => __( 'No file selected', '3pika-gallery' ), 'selectWm' => __( 'Select image', '3pika-gallery' ), 'use' => __( 'Use this image', '3pika-gallery' ), ), ) ); if ( 'tpika-new' === $page ) { wp_enqueue_media(); wp_enqueue_script( 'tpika-builder', TPIKA_URL . 'assets/admin/builder.js', array( 'jquery', 'jquery-ui-sortable', 'tpika-admin' ), TPIKA_VERSION, true ); $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification $g = $id ? TPIKA_Post_Type::get( $id ) : null; wp_localize_script( 'tpika-builder', 'TPIKA_BUILDER', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'tpika_admin' ), 'id' => $g ? $g['id'] : 0, 'title' => $g ? $g['title'] : '', 'images' => $g ? TPIKA_Post_Type::images_for_admin( $g['images'] ) : array(), 'filters' => $g ? $g['filters'] : array(), 'editUrl' => tpika_admin_url( 'tpika-new' ), 'previewNonceUrl' => home_url( '/' ), 'i18n' => array( 'addImages' => __( 'Add images', '3pika-gallery' ), 'useImages' => __( 'Add to gallery', '3pika-gallery' ), 'selectPoster' => __( 'Select poster image', '3pika-gallery' ), 'selectWm' => __( 'Select watermark image', '3pika-gallery' ), 'use' => __( 'Use this image', '3pika-gallery' ), 'saved' => __( 'Gallery saved.', '3pika-gallery' ), 'saving' => __( 'Saving…', '3pika-gallery' ), 'save' => __( 'Save Gallery', '3pika-gallery' ), 'error' => __( 'Could not save. Please try again.', '3pika-gallery' ), 'newFilter' => __( 'New filter', '3pika-gallery' ), /* translators: %d: number of selected items */ 'removeSelected' => __( 'Remove %d selected item(s) from the gallery?', '3pika-gallery' ), 'deleteFilter' => __( 'Delete this filter? It will be removed from all images.', '3pika-gallery' ), 'unsaved' => __( 'You have unsaved changes.', '3pika-gallery' ), 'invalidVideo' => __( 'Please enter a valid YouTube, Vimeo or MP4 URL.', '3pika-gallery' ), 'noFilters' => __( 'No filters yet. Create filters in the Filters tab.', '3pika-gallery' ), 'video' => __( 'Video', '3pika-gallery' ), 'copied' => __( 'Copied!', '3pika-gallery' ), /* translators: %d: number of items */ 'items' => __( '%d items', '3pika-gallery' ), /* translators: %d: number of selected items */ 'selected' => __( '%d selected', '3pika-gallery' ), 'titleRequired' => __( 'Please give the gallery a name.', '3pika-gallery' ), 'remove' => __( 'Remove', '3pika-gallery' ), 'deleteBtn' => __( 'Delete', '3pika-gallery' ), 'colorAuto' => __( 'Automatic: follows the accent color (Settings → Layout). Click to choose an own color.', '3pika-gallery' ), 'colorOwn' => __( 'Own color for this filter', '3pika-gallery' ), 'colorReset' => __( 'Back to automatic (accent color)', '3pika-gallery' ), 'textAuto' => __( 'Text color: automatic (black or white depending on the background). Click to choose.', '3pika-gallery' ), 'textOwn' => __( 'Own text color for this filter', '3pika-gallery' ), 'textReset' => __( 'Back to automatic text color', '3pika-gallery' ), 'all' => __( 'All', '3pika-gallery' ), 'noFilter' => __( 'No filter', '3pika-gallery' ), 'appliedAll' => __( 'Colors applied to all filters.', '3pika-gallery' ), 'selectVideo' => __( 'Select video', '3pika-gallery' ), 'useVideo' => __( 'Use this video', '3pika-gallery' ), ), ) ); } elseif ( 'tpika-settings' === $page ) { wp_enqueue_media(); } } /* ---------------- Pages ---------------- */ public function page_list() { include TPIKA_PATH . 'admin/views/list.php'; } public function page_builder() { $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification if ( $id && ! current_user_can( 'edit_post', $id ) ) { wp_die( esc_html__( 'You are not allowed to edit this gallery.', '3pika-gallery' ) ); } $gallery = $id ? TPIKA_Post_Type::get( $id ) : null; $settings = $gallery ? $gallery['settings'] : TPIKA_Settings::get(); include TPIKA_PATH . 'admin/views/builder.php'; } public function page_settings() { $settings = TPIKA_Settings::get(); include TPIKA_PATH . 'admin/views/settings.php'; } public function page_premium() { include TPIKA_PATH . 'admin/views/premium.php'; } /* ---------------- Field renderer (shared by builder + settings) ---------------- */ /** * Render one settings field row. * * @param string $key Key. * @param array $field Definition. * @param mixed $value Current value. */ public static function field( $key, $field, $value ) { $name = 's[' . $key . ']'; $id = 'tpg-f-' . $key; $class = 'tpg-field'; $extra = ''; // Extra attribute of the control. ?>
' . esc_html( $field['desc'] ) . '
'; } ?>