includes();
add_action( 'init', array( $this, 'init' ) );
add_action( 'template_redirect', array( $this, 'maybe_preview' ) );
add_filter( 'plugin_action_links_' . TPIKA_BASENAME, array( $this, 'action_links' ) );
add_filter( 'plugin_row_meta', array( $this, 'row_meta' ), 9, 2 ); // 9: before "Check for updates" of the updater.
add_filter( 'lang_dir_for_domain', array( $this, 'lang_dir' ), 10, 2 );
add_filter( 'load_textdomain_mofile', array( $this, 'mofile' ), 10, 2 );
add_filter( 'load_script_translation_file', array( $this, 'script_translation_file' ), 10, 3 );
new TPIKA_Ajax();
new TPIKA_Classic_Editor();
new TPIKA_Elementor();
new TPIKA_WPBakery();
if ( is_admin() ) {
new TPIKA_Admin_Menu();
}
}
private function includes() {
require_once TPIKA_PATH . 'includes/class-settings.php';
require_once TPIKA_PATH . 'includes/class-post-type.php';
require_once TPIKA_PATH . 'includes/class-editions.php';
require_once TPIKA_PATH . 'includes/class-renderer.php';
require_once TPIKA_PATH . 'includes/class-shortcode.php';
require_once TPIKA_PATH . 'includes/class-ajax.php';
require_once TPIKA_PATH . 'includes/class-admin-menu.php';
require_once TPIKA_PATH . 'includes/integrations/class-classic-editor.php';
require_once TPIKA_PATH . 'includes/integrations/class-gutenberg.php';
require_once TPIKA_PATH . 'includes/integrations/class-elementor.php';
require_once TPIKA_PATH . 'includes/integrations/class-wpbakery.php';
}
public function init() {
TPIKA_Post_Type::register();
TPIKA_Shortcode::register();
TPIKA_Renderer::register_assets();
TPIKA_Gutenberg::register();
}
/**
* A language pack installed by WordPress (wp-content/languages/plugins) always comes first.
* For a language without one, the translation shipped in the plugin's /languages folder is used.
*
* @param string|false $path Languages directory WordPress found.
* @param string $domain Text domain.
* @return string|false
*/
public function lang_dir( $path, $domain ) {
return ( ! $path && '3pika-gallery' === $domain ) ? TPIKA_PATH . 'languages/' : $path;
}
public function mofile( $mofile, $domain ) {
return '3pika-gallery' === $domain ? tpika_locale_fallback_file( $mofile ) : $mofile;
}
public function script_translation_file( $file, $handle, $domain ) {
return '3pika-gallery' === $domain ? tpika_locale_fallback_file( $file ) : $file;
}
/**
* Front-end preview for editors: /?tpika_preview=ID&_wpnonce=...
*/
public function maybe_preview() {
if ( empty( $_GET['tpika_preview'] ) ) {
return;
}
$tpika_id = absint( $_GET['tpika_preview'] );
if ( ! current_user_can( 'edit_post', $tpika_id ) || ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'tpika_preview_' . $tpika_id ) ) {
wp_die( esc_html__( 'You are not allowed to preview this gallery.', '3pika-gallery' ) );
}
$tpika_frame = ! empty( $_GET['tpika_frame'] );
add_action( 'wp_enqueue_scripts', array( $this, 'preview_assets' ) );
add_filter( 'show_admin_bar', '__return_false' );
nocache_headers();
include TPIKA_PATH . 'templates/preview.php';
exit;
}
public function preview_assets() {
wp_enqueue_style( 'tpika-preview', TPIKA_URL . 'assets/admin/preview.css', array(), TPIKA_VERSION );
wp_enqueue_script( 'tpika-preview', TPIKA_URL . 'assets/admin/preview.js', array(), TPIKA_VERSION, true );
}
public function action_links( $links ) {
$new = array(
'' . esc_html__( 'Galleries', '3pika-gallery' ) . '',
'' . esc_html__( 'Settings', '3pika-gallery' ) . '',
);
return array_merge( $new, $links );
}
/**
* Plugins screen, second row (Version | By … | Visit plugin site): link to the overview of the Premium edition.
*/
public function row_meta( $links, $file ) {
if ( TPIKA_BASENAME !== $file ) {
return $links;
}
$links[] = '' . esc_html__( 'Go Premium', '3pika-gallery' ) . '';
return $links;
}
public static function activate() {
require_once TPIKA_PATH . 'includes/class-settings.php';
if ( ! get_option( 'tpika_settings' ) ) {
add_option( 'tpika_settings', TPIKA_Settings::defaults() );
}
update_option( 'tpika_version', TPIKA_VERSION );
}
}