*/ class Falang { /** * The loader that's responsible for maintaining and registering all hooks that power * the plugin. * * @since 1.0.0 * @access protected * @var Falang_Loader $loader Maintains and registers all hooks for the plugin. */ protected $loader; /** * The unique identifier of this plugin. * * @since 1.0.0 * @access protected * @var string $plugin_name The string used to uniquely identify this plugin. */ protected $plugin_name; /** * The current version of the plugin. * * @since 1.0.0 * @access protected * @var string $version The current version of the plugin. */ protected $version; /** * Define the core functionality of the plugin. * * Set the plugin name and the plugin version that can be used throughout the plugin. * Load the dependencies, define the locale, and set the hooks for the admin area and * the public-facing side of the site. * * @since 1.0.0 */ public function __construct() { if ( defined( 'FALANG_VERSION' ) ) { $this->version = FALANG_VERSION; } else { $this->version = '1.0'; } $this->plugin_name = 'falang'; $this->load_dependencies(); $this->set_locale(); //add_action( 'init' , array( $this, 'register_taxonony' ), 9 ); $this->register_taxonony(); // Plugin initialization // Take no action before all plugins are loaded add_action( 'plugins_loaded', array( $this, 'init' ), 1 ); if (is_admin()) { $this->define_admin_hooks(); } else { $this->define_public_hooks(); } // setups post types to translate now it's in option of falang //add_action( 'registered_post_type', array( $this, 'registered_post_type' ) ); //TODO put this in class-falang-admin ?? //add local column on pages add_filter( 'manage_pages_columns', array( $this, 'falang_pages_columns' )); //add local column on posts add_filter( 'manage_posts_columns', array( $this, 'falang_posts_columns'), 10, 2 ); //display locale to posts on list add_action( 'manage_posts_custom_column', array( $this, 'falang_manage_posts_custom_column'), 10, 2 ); //display locale to page on list add_action( 'manage_pages_custom_column', array( $this, 'falang_manage_posts_custom_column'), 10, 2 ); add_action( 'save_post', array( $this, 'falang_save_post'), 10, 2); $this->add_admin_filters(); } /** * Load the required dependencies for this plugin. * * Include the following files that make up the plugin: * * - Falang_Loader. Orchestrates the hooks of the plugin. * - Falang_i18n. Defines internationalization functionality. * - Falang_Admin. Defines all hooks for the admin area. * - Falang_Public. Defines all hooks for the public side of the site. * * Create an instance of the loader which will be used to register the hooks * with WordPress. * * @since 1.0.0 * @access private */ private function load_dependencies() { /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-falang-loader.php'; /** * The class responsible for defining internationalization functionality * of the plugin. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-falang-i18n.php'; /** * The class responsible for defining all actions that occur in the admin area. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-falang-admin.php'; /** * The class responsible for defining all actions that occur in the public-facing * side of the site. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-falang-public.php'; $this->loader = new Falang_Loader(); } /** * Define the locale for this plugin for internationalization. * * Uses the Falang_i18n class in order to set the domain and to register the hook * with WordPress. * * @since 1.0.0 * @access private */ private function set_locale() { $plugin_i18n = new Falang_i18n(); $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); } /** * Register all of the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { global $falang_core; $falang_core = new Falang_Admin( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'admin_enqueue_scripts', $falang_core, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $falang_core, 'enqueue_scripts' ); $this->loader->add_action( 'admin_menu', $falang_core, 'add_admin_menu' ); } /** * Run the loader to execute all of the hooks with WordPress. * * @since 1.0.0 */ public function run() { $this->loader->run(); } /** * Register all of the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_public_hooks() { global $falang_core; $falang_core = new Falang_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wp_enqueue_scripts', $falang_core, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $falang_core, 'enqueue_scripts' ); } /** * The name of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. * * @since 1.0.0 * @return string The name of the plugin. */ public function get_plugin_name() { return $this->plugin_name; } /** * The reference to the class that orchestrates the hooks with the plugin. * * @since 1.0.0 * @return Falang_Loader Orchestrates the hooks of the plugin. */ public function get_loader() { return $this->loader; } /** * Retrieve the version number of the plugin. * * @since 1.0.0 * @return string The version number of the plugin. */ public function get_version() { return $this->version; } public function register_taxonony(){ $falang_model = new \Falang\Model\Falang_Model(); //register language taxonomy $language_args= array( 'hierarchical' => false, 'public' => false, 'show_ui' => false, // hide the taxonomy on admin side, needed for WP 4.4.x 'show_in_nav_menus' => false, 'publicly_queryable' => true, // since WP 4.5 'query_var' => 'lang', //TODO check this rewrite 'rewrite' => false, //'rewrite' => $this->model->options['force_lang'] < 2, // no rewrite for domains and sub-domains '_falang' => true, // falang taxonomy, 'labels' => array( 'name' => __( 'Languages', 'falang' ), 'singular_name' => __( 'Language', 'falang' ), 'all_items' => __( 'All languages', 'falang' ), ) ); register_taxonomy('language', $falang_model->get_translated_post_types(), $language_args); //register_language_groupe taxonomy register_taxonomy( 'languages_group', 'term', array( 'hierarchical' => false, 'update_count_callback' => '', 'show_ui' => false, 'label'=>false, 'rewrite' => false, '_builtin' => false, 'show_in_nav_menus' => false ) ); $args = array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false, '_falang' => true ); register_taxonomy( 'term_language', 'term', $args ); $args['update_count_callback'] = '_update_generic_term_count'; // count *all* posts to avoid deleting in clean_translations_terms register_taxonomy( 'term_translations', 'term', $args ); } public function add_admin_filters(){ add_action( 'wp_loaded', array( $this, 'add_filters' ), 5 ); } /** * Falang initialization * * * @since 1.1 */ public function init(){ if ( ! defined( 'FALANG_WPML_COMPAT' ) || FALANG_WPML_COMPAT ) { require_once FALANG_EXT . '/wpml/wpml-compat.php'; FALANG_WPML_COMPAT::instance(); // WPML API //FALANG_WPML_COMPAT::instance(); //TODO wpml-config.xml parisng not yet in use } } public function add_filters() { //TODO //add admin filter from namespace not array $classes = array( 'Classic_Editor'); $obj = strtolower( 'Classic_Editor' ); $this->obj = new \Falang\Filter\Admin\Classic_Editor($this); // foreach ( $classes as $class ) { // $obj = strtolower( $class ); // /** // * Filter the class to instantiate when loading admin filters // * // * @since 1.5 // * // * @param string $class class name // */ // $class = apply_filters( 'falang_' . $obj, $class ); // $class = "\Falang\Filter\Admin\".$class; // // $this->$obj = new $class( $this ); // } } /** * Check if registered post type must be translated * * @since 1.0 * * @param string $post_type post type name */ // public function registered_post_type( $post_type ) { // $falang_model = new \Falang\Model\Falang_Model(); // // if ( $falang_model->is_translated_post_type( $post_type ) ) { // register_taxonomy_for_object_type( 'language', $post_type ); // register_taxonomy_for_object_type( 'post_translations', $post_type ); // } // } public function falang_pages_columns($posts_columns){ return $this->falang_posts_columns( $posts_columns, 'page' ); } /* * Display locale and translate colum in post column * */ public function falang_posts_columns( $posts_columns, $post_type ) { $falang_model = new \Falang\Model\Falang_Model(); if ( ! $falang_model->is_translated_post_type( $post_type ) ) { return $posts_columns; } if ( ! isset( $posts_columns['locale'] ) ) { $posts_columns = array_merge( array_slice( $posts_columns, 0, 3 ), array( 'locale' => __( 'Locale', 'falang' ) ), array_slice( $posts_columns, 3 ) ); } if ( ! isset( $posts_columns['translation'] ) ) { $posts_columns = array_merge( array_slice( $posts_columns, 0, 3 ), array( 'translation' => __( 'Translation', 'falang' ) ), array_slice( $posts_columns, 3 ) ); } return $posts_columns; } /* * Display locale for a post in post column * */ public function falang_manage_posts_custom_column( $column_name, $post_id){ if ( 'locale' != $column_name && 'translation' != $column_name ) { return; } $post_type = get_post_type( $post_id ); //TODO check if it's necessary to make a test on is_translated_pos $falang_model = new \Falang\Model\Falang_Model(); if ( ! $falang_model->is_translated_post_type( $post_type ) ) { return; } $locale = get_post_meta( $post_id, '_locale', true ); if ('locale' == $column_name) { if ( ! empty( $locale ) ) { $language = $falang_model->get_language_by_locale( $locale ); //$language is not set if a specific local is set to the post // and language was removed with data not removed if (isset($language)){ echo esc_html($language->name); } else { echo __( 'Language removed :' .$locale, 'falang' ); } } else { echo __( 'All language', 'falang' ); } } if ('translation' == $column_name) { //display translation link for all or empty locale if ( empty( $locale ) || 'all' == $locale ) { $default_local = $falang_model->get_default_language()->locale; $languages = $falang_model->get_languages_list(array( 'hide_default' => true)); foreach ( $languages as $language ) { //don't display link for default language if ($language->locale != $default_local ) { //get status $post_status = get_post_meta($post_id,Falang_Core::get_prefix($language->locale).'published' , true); $status = 'dashicons dashicons-marker'; if (!empty($post_status)){ if ($post_status){ $status = 'dashicons dashicons-yes-alt'; } else { $status = 'dashicons dashicons-dismiss'; } } echo sprintf( '%3$s ', esc_url( add_query_arg( array( 'page' => 'falang-translation', 'language' => $language->locale, 'action' => 'edit', 'post_id' => $post_id ), 'admin.php') ), $status, $language->get_flag() ); } } } } } public function falang_save_post($post_id, $post){ $falang_model = new \Falang\Model\Falang_Model(); if (!$falang_model->is_translated_post_type($post->post_type)) { return false; } //TODO find why there are a waring on woocommerce without the check if (!isset($_POST['post_locale_choice'])){return false;} $current_locales = get_post_meta( $post_id, '_locale' ); $locale = null; $locale = sanitize_html_class($_POST['post_locale_choice']); //add local exist and not same ass previous //if new local is all remove it if (!empty($locale) && ($current_locales != $locale)) { if ($locale == 'all'){ delete_post_meta($post_id,'_locale'); } else { update_post_meta( $post_id, '_locale', strip_tags($locale) ); } return true; } return false; } }