$post ) : array() ); } wp_add_inline_script( 'threece-inserter', 'window.threeceInserterData = ' . wp_json_encode( array( 'root' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'postId' => $post ? (int) $post->ID : 0, 'shortcodeUrl' => THREECE_URL . 'assets/js/shortcode.js?ver=' . rawurlencode( THREECE_VERSION ), 'searchUrl' => THREECE_URL . 'assets/js/inserter-search.js?ver=' . rawurlencode( THREECE_VERSION ), // The preview shows elements in the chosen style; the accent is one fixed palette value or empty. 'design' => array( 'style' => $design['style'], 'accent' => ThreeCE_Design::accents()[ $design['accent'] ] ?? '', ), 'emojiUrl' => THREECE_URL . 'assets/emoji/' . self::emoji_language( get_user_locale() ) . '.json?ver=' . rawurlencode( THREECE_VERSION ), 'emojiSearchUrl' => THREECE_URL . 'assets/js/emoji-search.js?ver=' . rawurlencode( THREECE_VERSION ), 'tableStyleUrl' => THREECE_URL . 'assets/js/table-style.js?ver=' . rawurlencode( THREECE_VERSION ), 'tablePasteUrl' => THREECE_URL . 'assets/js/table-paste.js?ver=' . rawurlencode( THREECE_VERSION ), 'i18n' => array( 'title' => __( 'Insert element', '3task-toolbar-for-classic-editor' ), 'elementButton' => __( 'Element', '3task-toolbar-for-classic-editor' ), 'otherShortcodes' => __( 'Other shortcodes on this site', '3task-toolbar-for-classic-editor' ), 'search' => __( 'Search elements', '3task-toolbar-for-classic-editor' ), 'searchPlaceholder' => __( 'Search, for example table, FAQ, button', '3task-toolbar-for-classic-editor' ), 'groups' => __( 'Groups', '3task-toolbar-for-classic-editor' ), 'recent' => __( 'Recently used', '3task-toolbar-for-classic-editor' ), 'results' => __( 'Search results', '3task-toolbar-for-classic-editor' ), 'noResults' => __( 'No element matches. Try another word, or close this window and use the toolbar.', '3task-toolbar-for-classic-editor' ), 'back' => __( 'All elements', '3task-toolbar-for-classic-editor' ), /* translators: %s: name of the element, for example "Video" */ 'insertNamed' => __( 'Insert %s', '3task-toolbar-for-classic-editor' ), 'previewNote' => __( 'as it will appear in the post', '3task-toolbar-for-classic-editor' ), 'shortcode' => __( 'Shortcode', '3task-toolbar-for-classic-editor' ), 'keysList' => __( 'Arrow keys choose, Enter opens', '3task-toolbar-for-classic-editor' ), 'keysForm' => __( 'Esc goes back to all elements', '3task-toolbar-for-classic-editor' ), 'content' => __( 'Content', '3task-toolbar-for-classic-editor' ), 'add' => __( 'Add', '3task-toolbar-for-classic-editor' ), 'remove' => __( 'Remove', '3task-toolbar-for-classic-editor' ), 'chooseImage' => __( 'Choose image', '3task-toolbar-for-classic-editor' ), 'replaceImage' => __( 'Replace image', '3task-toolbar-for-classic-editor' ), 'removeImage' => __( 'Remove image', '3task-toolbar-for-classic-editor' ), 'mediaTitle' => __( 'Choose preview image', '3task-toolbar-for-classic-editor' ), 'mediaButton' => __( 'Use this image', '3task-toolbar-for-classic-editor' ), 'preview' => __( 'Preview', '3task-toolbar-for-classic-editor' ), 'insert' => __( 'Insert', '3task-toolbar-for-classic-editor' ), 'cancel' => __( 'Cancel', '3task-toolbar-for-classic-editor' ), 'close' => __( 'Close', '3task-toolbar-for-classic-editor' ), 'otherHint' => __( 'This shortcode comes from another plugin or your theme. It is inserted without settings.', '3task-toolbar-for-classic-editor' ), 'previewFailed' => __( 'The preview could not be loaded.', '3task-toolbar-for-classic-editor' ), 'loadFailed' => __( 'The element dialog could not be loaded. Please reload the page.', '3task-toolbar-for-classic-editor' ), 'emojiTitle' => __( 'Insert emoji', '3task-toolbar-for-classic-editor' ), 'emojiButton' => __( 'Emoji', '3task-toolbar-for-classic-editor' ), 'emojiSearch' => __( 'Search emoji', '3task-toolbar-for-classic-editor' ), 'emojiRecent' => __( 'Recently used', '3task-toolbar-for-classic-editor' ), 'emojiResults' => __( 'Search results', '3task-toolbar-for-classic-editor' ), 'emojiNone' => __( 'No emoji found.', '3task-toolbar-for-classic-editor' ), 'emojiLoadFailed' => __( 'The emoji could not be loaded. Please reload the page.', '3task-toolbar-for-classic-editor' ), 'table' => self::table_texts(), ), ) ) . ';', 'before' ); } /** * Texts of the table style dialog, including the sample table of the previews. * * @return array */ private static function table_texts() { return array( 'title' => __( 'Table style', '3task-toolbar-for-classic-editor' ), 'textButton' => __( 'Table', '3task-toolbar-for-classic-editor' ), 'noTable' => __( 'There is no table at the cursor. “Insert table” adds a new table in the chosen style. To change an existing table, close this window, click into the table and open it again. Below you can also paste a table from Excel, Google Sheets or a CSV file.', '3task-toolbar-for-classic-editor' ), 'insertTable' => __( 'Insert table', '3task-toolbar-for-classic-editor' ), /* translators: %d: column number */ 'column' => __( 'Column %d', '3task-toolbar-for-classic-editor' ), 'templates' => __( 'Template', '3task-toolbar-for-classic-editor' ), 'options' => __( 'Options', '3task-toolbar-for-classic-editor' ), 'accent' => __( 'Accent color', '3task-toolbar-for-classic-editor' ), 'phone' => __( 'On phones', '3task-toolbar-for-classic-editor' ), 'sortable' => __( 'Visitors can sort the columns', '3task-toolbar-for-classic-editor' ), 'apply' => __( 'Apply', '3task-toolbar-for-classic-editor' ), 'insert' => __( 'Insert pasted cells as table', '3task-toolbar-for-classic-editor' ), 'pasteTitle' => __( 'New table from Excel, Google Sheets or CSV', '3task-toolbar-for-classic-editor' ), 'pasteLabel' => __( 'Copy the cells in your spreadsheet and paste them here.', '3task-toolbar-for-classic-editor' ), 'firstRowHeader' => __( 'First row is the header', '3task-toolbar-for-classic-editor' ), /* translators: 1: number of rows, 2: number of columns */ 'found' => __( '%1$s rows, %2$s columns', '3task-toolbar-for-classic-editor' ), 'errors' => array( 'empty' => __( 'No cells found.', '3task-toolbar-for-classic-editor' ), 'too-many-rows' => __( 'At most 500 rows, please split the table.', '3task-toolbar-for-classic-editor' ), 'too-many-columns' => __( 'At most 50 columns.', '3task-toolbar-for-classic-editor' ), ), 'presets' => array( 'clean' => __( 'Clean', '3task-toolbar-for-classic-editor' ), 'striped' => __( 'Striped', '3task-toolbar-for-classic-editor' ), 'grid' => __( 'Grid', '3task-toolbar-for-classic-editor' ), 'minimal' => __( 'Minimal', '3task-toolbar-for-classic-editor' ), 'header' => __( 'Colored header', '3task-toolbar-for-classic-editor' ), 'pricing' => __( 'Price list', '3task-toolbar-for-classic-editor' ), 'compare' => __( 'Comparison', '3task-toolbar-for-classic-editor' ), 'compact' => __( 'Compact', '3task-toolbar-for-classic-editor' ), ), 'switches' => array( 'head' => __( 'Highlight header row', '3task-toolbar-for-classic-editor' ), 'firstcol' => __( 'First column bold', '3task-toolbar-for-classic-editor' ), 'zebra' => __( 'Stripes', '3task-toolbar-for-classic-editor' ), 'hover' => __( 'Highlight row under the pointer', '3task-toolbar-for-classic-editor' ), 'numbers' => __( 'Numbers right-aligned', '3task-toolbar-for-classic-editor' ), 'dense' => __( 'Compact rows', '3task-toolbar-for-classic-editor' ), ), 'accents' => array( 'theme' => __( 'From the theme', '3task-toolbar-for-classic-editor' ) ) + ThreeCE_Design::accent_labels(), 'phones' => array( 'scroll' => __( 'Scroll sideways', '3task-toolbar-for-classic-editor' ), 'stack' => __( 'Show rows as cards', '3task-toolbar-for-classic-editor' ), ), 'sampleHead' => array( __( 'Package', '3task-toolbar-for-classic-editor' ), __( 'Pages', '3task-toolbar-for-classic-editor' ), __( 'Price', '3task-toolbar-for-classic-editor' ) ), 'sampleRows' => array( array( __( 'Start', '3task-toolbar-for-classic-editor' ), '5', '900' ), array( __( 'Business', '3task-toolbar-for-classic-editor' ), '8', '1,600' ), array( __( 'Shop', '3task-toolbar-for-classic-editor' ), '15', '3,200' ), array( __( 'Portal', '3task-toolbar-for-classic-editor' ), '25', '5,400' ), ), ); } /** * Only users who write posts get the button. */ private static function allowed(): bool { return current_user_can( 'edit_posts' ); } /** * Adds the button to the first toolbar row, after all other buttons. * * @param mixed $buttons Toolbar buttons from the filter. * @param mixed $editor_id Editor ID from the filter; only the editors ThreeCE_Toolbar::applies_to() names. * @return mixed */ public static function toolbar_button( $buttons, $editor_id = '' ) { if ( ! is_array( $buttons ) || ! self::allowed() || ! ThreeCE_Toolbar::applies_to( $editor_id ) ) { return $buttons; } foreach ( array( self::BUTTON, self::EMOJI_BUTTON ) as $button ) { if ( ! in_array( $button, $buttons, true ) ) { $buttons[] = $button; } } return $buttons; } /** * Emoji language file for a WordPress locale: emojibase names (de, en-gb, zh-hant …), English otherwise. * * @param string $locale Locale such as de_DE_formal. * @return string */ public static function emoji_language( $locale ) { $locale = strtolower( str_replace( '_', '-', (string) $locale ) ); $special = array( 'en-gb' => 'en-gb', 'es-mx' => 'es-mx', 'zh-tw' => 'zh-hant', 'zh-hk' => 'zh-hant', 'nn' => 'nb', ); foreach ( $special as $prefix => $language ) { if ( 0 === strpos( $locale, $prefix ) ) { return $language; } } $language = (string) strtok( $locale, '-' ); return preg_match( '#^[a-z]{2,3}$#', $language ) && is_file( THREECE_DIR . 'assets/emoji/' . $language . '.json' ) ? $language : 'en'; } /** * Registers the TinyMCE plugin that draws the toolbar button. * * @param mixed $plugins External TinyMCE plugins from the filter. * @return mixed */ public static function tinymce_plugin( $plugins ) { if ( ! is_array( $plugins ) || ! self::allowed() ) { return $plugins; } $plugins[ self::BUTTON ] = THREECE_URL . 'assets/js/tinymce-plugin.js?ver=' . rawurlencode( THREECE_VERSION ); return $plugins; } /** * Button next to "Add Media"; works in the Visual and the Text tab. * * @param string $editor_id Editor ID. */ public static function media_button( $editor_id = 'content' ): void { if ( ! self::allowed() ) { return; } printf( '', esc_attr( (string) $editor_id ), esc_html__( 'Insert element', '3task-toolbar-for-classic-editor' ) ); } }