ation', rest_url( $this->namespace . '/' . $this->rest_base . '/' . $term->term_id ) ); return $response; } /** * Updates a single term from a taxonomy. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function update_item( $request ) { $term = $this->get_term( $request['id'] ); if ( is_wp_error( $term ) ) { return $term; } if ( isset( $request['parent'] ) ) { if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); } $parent = get_term( (int) $request['parent'], $this->taxonomy ); if ( ! $parent ) { return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) ); } } $prepared_term = $this->prepare_item_for_database( $request ); // Only update the term if we have something to update. if ( ! empty( $prepared_term ) ) { if ( ! isset( $prepared_term->{'menu-name'} ) ) { // wp_update_nav_menu_object() requires that the menu-name is always passed. $prepared_term->{'menu-name'} = $term->name; } $update = wp_update_nav_menu_object( $term->term_id, wp_slash( (array) $prepared_term ) ); if ( is_wp_error( $update ) ) { return $update; } } $term = get_term( $term->term_id, $this->taxonomy ); /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */ do_action( "rest_insert_{$this->taxonomy}", $term, $request, false ); $schema = $this->get_item_schema(); if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { $meta_update = $this->meta->update_value( $request['meta'], $term->term_id ); if ( is_wp_error( $meta_update ) ) { return $meta_update; } } $locations_update = $this->handle_locations( $term->term_id, $request ); if ( is_wp_error( $locations_update ) ) { return $locations_update; } $this->handle_auto_add( $term->term_id, $request ); $fields_update = $this->update_additional_fields_for_object( $term, $request ); if ( is_wp_error( $fields_update ) ) { return $fields_update; } $request->set_param( 'context', 'view' ); /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */ do_action( "rest_after_insert_{$this->taxonomy}", $term, $request, false ); $response = $this->prepare_item_for_response( $term, $request ); return rest_ensure_response( $response ); } /** * Deletes a single term from a taxonomy. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function delete_item( $request ) { $term = $this->get_term( $request['id'] ); if ( is_wp_error( $term ) ) { return $term; } // We don't support trashing for terms. if ( ! $request['force'] ) { /* translators: %s: force=true */ return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Menus do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); } $request->set_param( 'context', 'view' ); $previous = $this->prepare_item_for_response( $term, $request ); $result = wp_delete_nav_menu( $term ); if ( ! $result || is_wp_error( $result ) ) { return new WP_Error( 'rest_cannot_delete', __( 'The menu cannot be deleted.' ), array( 'status' => 500 ) ); } $response = new WP_REST_Response(); $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data(), ) ); /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */ do_action( "rest_delete_{$this->taxonomy}", $term, $response, $request ); return $response; } /** * Returns the value of a menu's auto_add setting. * * @since 5.9.0 * * @param int $menu_id The menu id to query. * @return bool The value of auto_add. */ protected function get_menu_auto_add( $menu_id ) { $nav_menu_option = (array) get_option( 'nav_menu_options', array( 'auto_add' => array() ) ); return in_array( $menu_id, $nav_menu_option['auto_add'], true ); } /** * Updates the menu's auto add from a REST request. * * @since 5.9.0 * * @param int $menu_id The menu id to update. * @param WP_REST_Request $request Full details about the request. * @return bool True if the auto add setting was successfully updated. */ protected function handle_auto_add( $menu_id, $request ) { if ( ! isset( $request['auto_add'] ) ) { return true; } $nav_menu_option = (array) get_option( 'nav_menu_options', array( 'auto_add' => array() ) ); if ( ! isset( $nav_menu_option['auto_add'] ) ) { $nav_menu_option['auto_add'] = array(); } $auto_add = $request['auto_add']; $i = array_search( $menu_id, $nav_menu_option['auto_add'], true ); if ( $auto_add && false === $i ) { $nav_menu_option['auto_add'][] = $menu_id; } elseif ( ! $auto_add && false !== $i ) { array_splice( $nav_menu_option['auto_add'], $i, 1 ); } $update = update_option( 'nav_menu_options', $nav_menu_option ); /** This action is documented in wp-includes/nav-menu.php */ do_action( 'wp_update_nav_menu', $menu_id ); return $update; } /** * Returns the names of the locations assigned to the menu. * * @since 5.9.0 * * @param int $menu_id The menu id. * @return string[] The locations assigned to the menu. */ protected function get_menu_locations( $menu_id ) { $locations = get_nav_menu_locations(); $menu_locations = array(); foreach ( $locations as $location => $assigned_menu_id ) { if ( $menu_id === $assigned_menu_id ) { $menu_locations[] = $location; } } return $menu_locations; } /** * Updates the menu's locations from a REST request. * * @since 5.9.0 * * @param int $menu_id The menu id to update. * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True on success, a WP_Error on an error updating any of the locations. */ protected function handle_locations( $menu_id, $request ) { if ( ! isset( $request['locations'] ) ) { return true; } $menu_locations = get_registered_nav_menus(); $menu_locations = array_keys( $menu_locations ); $new_locations = array(); foreach ( $request['locations'] as $location ) { if ( ! in_array( $location, $menu_locations, true ) ) { return new WP_Error( 'rest_invalid_menu_location', __( 'Invalid menu location.' ), array( 'status' => 400, 'location' => $location, ) ); } $new_locations[ $location ] = $menu_id; } $assigned_menu = get_nav_menu_locations(); foreach ( $assigned_menu as $location => $term_id ) { if ( $term_id === $menu_id ) { unset( $assigned_menu[ $location ] ); } } $new_assignments = array_merge( $assigned_menu, $new_locations ); set_theme_mod( 'nav_menu_locations', $new_assignments ); return true; } /** * Retrieves the term's schema, conforming to JSON Schema. * * @since 5.9.0 * * @return array Item schema data. */ public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $schema = parent::get_item_schema(); unset( $schema['properties']['count'], $schema['properties']['link'], $schema['properties']['taxonomy'] ); $schema['properties']['locations'] = array( 'description' => __( 'The locations assigned to the menu.' ), 'type' => 'array', 'items' => array( 'type' => 'string', ), 'context' => array( 'view', 'edit' ), 'arg_options' => array( 'validate_callback' => static function ( $locations, $request, $param ) { $valid = rest_validate_request_arg( $locations, $request, $param ); if ( true !== $valid ) { return $valid; } $locations = rest_sanitize_request_arg( $locations, $request, $param ); foreach ( $locations as $location ) { if ( ! array_key_exists( $location, get_registered_nav_menus() ) ) { return new WP_Error( 'rest_invalid_menu_location', __( 'Invalid menu location.' ), array( 'location' => $location, ) ); } } return true; }, ), ); $schema['properties']['auto_add'] = array( 'description' => __( 'Whether to automatically add top level pages to this menu.' ), 'context' => array( 'view', 'edit' ), 'type' => 'boolean', ); $this->schema = $schema; return $this->add_additional_fields_schema( $this->schema ); } } = new GP_Locale(); $mrj->english_name = 'Mari (Hill)'; $mrj->native_name = 'Кырык мары'; $mrj->lang_code_iso_639_3 = 'mrj'; $mrj->country_code = 'ru'; $mrj->slug = 'mrj'; $mrj->alphabet = 'cyrillic'; $ms = new GP_Locale(); $ms->english_name = 'Malay'; $ms->native_name = 'Bahasa Melayu'; $ms->lang_code_iso_639_1 = 'ms'; $ms->lang_code_iso_639_2 = 'msa'; $ms->wp_locale = 'ms_MY'; $ms->slug = 'ms'; $ms->nplurals = 1; $ms->plural_expression = '0'; $ms->google_code = 'ms'; $ms->facebook_locale = 'ms_MY'; $mwl = new GP_Locale(); $mwl->english_name = 'Mirandese'; $mwl->native_name = 'Mirandés'; $mwl->lang_code_iso_639_2 = 'mwl'; $mwl->slug = 'mwl'; $my = new GP_Locale(); $my->english_name = 'Myanmar (Burmese)'; $my->native_name = 'ဗမာစာ'; $my->lang_code_iso_639_1 = 'my'; $my->lang_code_iso_639_2 = 'mya'; $my->country_code = 'mm'; $my->wp_locale = 'my_MM'; $my->slug = 'mya'; $my->google_code = 'my'; $my->alphabet = 'burmese'; $ne = new GP_Locale(); $ne->english_name = 'Nepali'; $ne->native_name = 'नेपाली'; $ne->lang_code_iso_639_1 = 'ne'; $ne->lang_code_iso_639_2 = 'nep'; $ne->country_code = 'np'; $ne->wp_locale = 'ne_NP'; $ne->slug = 'ne'; $ne->google_code = 'ne'; $ne->facebook_locale = 'ne_NP'; $ne->alphabet = 'devanagari'; $nb = new GP_Locale(); $nb->english_name = 'Norwegian (Bokmål)'; $nb->native_name = 'Norsk bokmål'; $nb->lang_code_iso_639_1 = 'nb'; $nb->lang_code_iso_639_2 = 'nob'; $nb->country_code = 'no'; $nb->wp_locale = 'nb_NO'; $nb->slug = 'nb'; $nb->google_code = 'no'; $nb->facebook_locale = 'nb_NO'; $nl = new GP_Locale(); $nl->english_name = 'Dutch'; $nl->native_name = 'Nederlands'; $nl->lang_code_iso_639_1 = 'nl'; $nl->lang_code_iso_639_2 = 'nld'; $nl->country_code = 'nl'; $nl->wp_locale = 'nl_NL'; $nl->slug = 'nl'; $nl->google_code = 'nl'; $nl->facebook_locale = 'nl_NL'; $nl_be = new GP_Locale(); $nl_be->english_name = 'Dutch (Belgium)'; $nl_be->native_name = 'Nederlands (België)'; $nl_be->lang_code_iso_639_1 = 'nl'; $nl_be->lang_code_iso_639_2 = 'nld'; $nl_be->country_code = 'be'; $nl_be->wp_locale = 'nl_BE'; $nl_be->slug = 'nl-be'; $nl_be->google_code = 'nl'; $no = new GP_Locale(); $no->english_name = 'Norwegian'; $no->native_name = 'Norsk'; $no->lang_code_iso_639_1 = 'no'; $no->lang_code_iso_639_2 = 'nor'; $no->country_code = 'no'; $no->slug = 'no'; $no->google_code = 'no'; $nn = new GP_Locale(); $nn->english_name = 'Norwegian (Nynorsk)'; $nn->native_name = 'Norsk nynorsk'; $nn->lang_code_iso_639_1 = 'nn'; $nn->lang_code_iso_639_2 = 'nno'; $nn->country_code = 'no'; $nn->wp_locale = 'nn_NO'; $nn->slug = 'nn'; $nn->google_code = 'no'; $nn->facebook_locale = 'nn_NO'; $nqo = new GP_Locale(); $nqo->english_name = 'N’ko'; $nqo->native_name = 'ߒߞߏ'; $nqo->lang_code_iso_639_2 = 'nqo'; $nqo->lang_code_iso_639_3 = 'nqo'; $nqo->country_code = 'gn'; $nqo->wp_locale = 'nqo'; $nqo->slug = 'nqo'; $nqo->text_direction = 'rtl'; $nqo->alphabet = 'nko'; $nso = new GP_Locale(); $nso->english_name = 'Northern Sotho'; $nso->native_name = 'Sesotho sa Leboa'; $nso->lang_code_iso_639_2 = 'nso'; $nso->lang_code_iso_639_3 = 'nso'; $nso->country_code = 'za'; $nso->slug = 'nso'; $oci = new GP_Locale(); $oci->english_name = 'Occitan'; $oci->native_name = 'Occitan'; $oci->lang_code_iso_639_1 = 'oc'; $oci->lang_code_iso_639_2 = 'oci'; $oci->country_code = 'fr'; $oci->wp_locale = 'oci'; $oci->slug = 'oci'; $oci->nplurals = 2; $oci->plural_expression = 'n > 1'; $orm = new GP_Locale(); $orm->english_name = 'Oromo'; $orm->native_name = 'Afaan Oromo'; $orm->lang_code_iso_639_1 = 'om'; $orm->lang_code_iso_639_2 = 'orm'; $orm->lang_code_iso_639_3 = 'orm'; $orm->slug = 'orm'; $orm->plural_expression = 'n > 1'; $ory = new GP_Locale(); $ory->english_name = 'Oriya'; $ory->native_name = 'ଓଡ଼ିଆ'; $ory->lang_code_iso_639_1 = 'or'; $ory->lang_code_iso_639_2 = 'ory'; $ory->country_code = 'in'; $ory->wp_locale = 'ory'; $ory->slug = 'ory'; $ory->facebook_locale = 'or_IN'; $ory->alphabet = 'odia'; $os = new GP_Locale(); $os->english_name = 'Ossetic'; $os->native_name = 'Ирон'; $os->lang_code_iso_639_1 = 'os'; $os->lang_code_iso_639_2 = 'oss'; $os->wp_locale = 'os'; $os->slug = 'os'; $os->alphabet = 'cyrillic'; $pa = new GP_Locale(); $pa->english_name = 'Panjabi (India)'; $pa->native_name = 'ਪੰਜਾਬੀ'; $pa->lang_code_iso_639_1 = 'pa'; $pa->lang_code_iso_639_2 = 'pan'; $pa->country_code = 'in'; $pa->wp_locale = 'pa_IN'; $pa->slug = 'pa'; $pa->google_code = 'pa'; $pa->nplurals = 2; $pa->plural_expression = 'n > 1'; $pa->facebook_locale = 'pa_IN'; $pa->alphabet = 'gurmukhi'; $pa_pk = new GP_Locale(); $pa_pk->english_name = 'Punjabi (Pakistan)'; $pa_pk->native_name = 'پنجابی'; $pa_pk->lang_code_iso_639_1 = 'pa'; $pa_pk->lang_code_iso_639_2 = 'pan'; $pa_pk->country_code = 'pk'; $pa_pk->wp_locale = 'pa_PK'; $pa_pk->slug = 'pa-pk'; $pa_pk->nplurals = 2; $pa_pk->plural_expression = 'n > 1'; $pa_pk->google_code = 'pa'; $pa_pk->alphabet = 'shahmukhi'; $pap_cw = new GP_Locale(); $pap_cw->english_name = 'Papiamento (Curaçao and Bonaire)'; $pap_cw->native_name = 'Papiamentu'; $pap_cw->lang_code_iso_639_2 = 'pap'; $pap_cw->lang_code_iso_639_3 = 'pap'; $pap_cw->country_code = 'cw'; $pap_cw->wp_locale = 'pap_CW'; $pap_cw->slug = 'pap-cw'; $pap_aw = new GP_Locale(); $pap_aw->english_name = 'Papiamento (Aruba)'; $pap_aw->native_name = 'Papiamento'; $pap_aw->lang_code_iso_639_2 = 'pap'; $pap_aw->lang_code_iso_639_3 = 'pap'; $pap_aw->country_code = 'aw'; $pap_aw->wp_locale = 'pap_AW'; $pap_aw->slug = 'pap-aw'; $pcd = new GP_Locale(); $pcd->english_name = 'Picard'; $pcd->native_name = 'Ch’ti'; $pcd->lang_code_iso_639_3 = 'pcd'; $pcd->country_code = 'fr'; $pcd->wp_locale = 'pcd'; $pcd->slug = 'pcd'; $pcd->nplurals = 2; $pcd->plural_expression = 'n > 1'; $pcm = new GP_Locale(); $pcm->english_name = 'Nigerian Pidgin'; $pcm->native_name = 'Nigerian Pidgin'; $pcm->lang_code_iso_639_3 = 'pcm'; $pcm->country_code = 'ng'; $pcm->wp_locale = 'pcm'; $pcm->slug = 'pcm'; $pirate = new GP_Locale(); $pirate->english_name = 'English (Pirate)'; $pirate->native_name = 'English (Pirate)'; $pirate->lang_code_iso_639_2 = 'art'; $pirate->wp_locale = 'art_xpirate'; $pirate->slug = 'pirate'; $pirate->google_code = 'xx-pirate'; $pirate->facebook_locale = 'en_PI'; $pl = new GP_Locale(); $pl->english_name = 'Polish'; $pl->native_name = 'Polski'; $pl->lang_code_iso_639_1 = 'pl'; $pl->lang_code_iso_639_2 = 'pol'; $pl->country_code = 'pl'; $pl->wp_locale = 'pl_PL'; $pl->slug = 'pl'; $pl->nplurals = 3; $pl->plural_expression = '(n == 1) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2)'; $pl->google_code = 'pl'; $pl->facebook_locale = 'pl_PL'; $pt = new GP_Locale(); $pt->english_name = 'Portuguese (Portugal)'; $pt->native_name = 'Português'; $pt->lang_code_iso_639_1 = 'pt'; $pt->country_code = 'pt'; $pt->wp_locale = 'pt_PT'; $pt->slug = 'pt'; $pt->google_code = 'pt-PT'; $pt->facebook_locale = 'pt_PT'; $pt_ao90 = new GP_Locale(); $pt_ao90->english_name = 'Portuguese (Portugal, AO90)'; $pt_ao90->native_name = 'Português (AO90)'; $pt_ao90->lang_code_iso_639_1 = 'pt'; $pt_ao90->country_code = 'pt'; $pt_ao90->wp_locale = 'pt_PT_ao90'; $pt_ao90->slug = 'pt-ao90'; $pt_ao90->google_code = 'pt-PT'; $pt_ao = new GP_Locale(); $pt_ao->english_name = 'Portuguese (Angola)'; $pt_ao->native_name = 'Português de Angola'; $pt_ao->lang_code_iso_639_1 = 'pt'; $pt_ao->country_code = 'ao'; $pt_ao->wp_locale = 'pt_AO'; $pt_ao->slug = 'pt-ao'; $pt_br = new GP_Locale(); $pt_br->english_name = 'Portuguese (Brazil)'; $pt_br->native_name = 'Português do Brasil'; $pt_br->lang_code_iso_639_1 = 'pt'; $pt_br->lang_code_iso_639_2 = 'por'; $pt_br->country_code = 'br'; $pt_br->wp_locale = 'pt_BR'; $pt_br->slug = 'pt-br'; $pt_br->nplurals = 2; $pt_br->plural_expression = 'n > 1'; $pt_br->google_code = 'pt-BR'; $pt_br->facebook_locale = 'pt_BR'; $ps = new GP_Locale(); $ps->english_name = 'Pashto'; $ps->native_name = 'پښتو'; $ps->lang_code_iso_639_1 = 'ps'; $ps->lang_code_iso_639_2 = 'pus'; $ps->country_code = 'af'; $ps->wp_locale = 'ps'; $ps->slug = 'ps'; $ps->text_direction = 'rtl'; $ps->facebook_locale = 'ps_AF'; $ps->alphabet = 'pashto'; $rhg = new GP_Locale(); $rhg->english_name = 'Rohingya'; $rhg->native_name = 'Ruáinga'; $rhg->lang_code_iso_639_3 = 'rhg'; $rhg->country_code = 'mm'; $rhg->wp_locale = 'rhg'; $rhg->slug = 'rhg'; $rhg->nplurals = 1; $rhg->plural_expression = '0'; $rif = new GP_Locale(); $rif->english_name = 'Tarifit'; $rif->native_name = 'Tarifiyt'; $rif->lang_code_iso_639_3 = 'rif'; $rif->country_code = 'ma'; $rif->slug = 'rif'; $ro = new GP_Locale(); $ro->english_name = 'Romanian'; $ro->native_name = 'Română'; $ro->lang_code_iso_639_1 = 'ro'; $ro->lang_code_iso_639_2 = 'ron'; $ro->country_code = 'ro'; $ro->wp_locale = 'ro_RO'; $ro->slug = 'ro'; $ro->nplurals = 3; $ro->plural_expression = '(n == 1) ? 0 : ((n == 0 || n % 100 >= 2 && n % 100 <= 19) ? 1 : 2)'; $ro->google_code = 'ro'; $ro->facebook_locale = 'ro_RO'; $roh = new GP_Locale(); $roh->english_name = 'Romansh'; $roh->native_name = 'Rumantsch'; $roh->lang_code_iso_639_1 = 'rm'; $roh->lang_code_iso_639_2 = 'roh'; $roh->lang_code_iso_639_3 = 'roh'; $roh->country_code = 'ch'; $roh->wp_locale = 'roh'; $roh->slug = 'roh'; $ru = new GP_Locale(); $ru->english_name = 'Russian'; $ru->native_name = 'Русский'; $ru->lang_code_iso_639_1 = 'ru'; $ru->lang_code_iso_639_2 = 'rus'; $ru->country_code = 'ru'; $ru->wp_locale = 'ru_RU'; $ru->slug = 'ru'; $ru->nplurals = 3; $ru->plural_expression = '(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2)'; $ru->google_code = 'ru'; $ru->facebook_locale = 'ru_RU'; $ru->alphabet = 'cyrillic'; $rue = new GP_Locale(); $rue->english_name = 'Rusyn'; $rue->native_name = 'Русиньскый'; $rue->lang_code_iso_639_3 = 'rue'; $rue->slug = 'rue'; $rue->nplurals = 3; $rue->plural_expression = '(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2)'; $rue->alphabet = 'cyrillic'; $rup = new GP_Locale(); $rup->english_name = 'Aromanian'; $rup->native_name = 'Armãneashce'; $rup->lang_code_iso_639_2 = 'rup'; $rup->lang_code_iso_639_3 = 'rup'; $rup->country_code = 'mk'; $rup->slug = 'rup'; $sah = new GP_Locale(); $sah->english_name = 'Sakha'; $sah->native_name = 'Сахалыы'; $sah->lang_code_iso_639_2 = 'sah'; $sah->lang_code_iso_639_3 = 'sah'; $sah->country_code = 'ru'; $sah->wp_locale = 'sah'; $sah->slug = 'sah'; $sah->alphabet = 'cyrillic'; $sa_in = new GP_Locale(); $sa_in->english_name = 'Sanskrit'; $sa_in->native_name = 'भारतम्'; $sa_in->lang_code_iso_639_1 = 'sa'; $sa_in->lang_code_iso_639_2 = 'san'; $sa_in->lang_code_iso_639_3 = 'san'; $sa_in->country_code = 'in'; $sa_in->wp_locale = 'sa_IN'; $sa_in->slug = 'sa-in'; $sa_in->facebook_locale = 'sa_IN'; $sa_in->alphabet = 'brahmic'; $scn = new GP_Locale(); $scn->english_name = 'Sicilian'; $scn->native_name = 'Sicilianu'; $scn->lang_code_iso_639_3 = 'scn'; $scn->country_code = 'it'; $scn->wp_locale = 'scn'; $scn->slug = 'scn'; $si = new GP_Locale(); $si->english_name = 'Sinhala'; $si->native_name = 'සිංහල'; $si->lang_code_iso_639_1 = 'si'; $si->lang_code_iso_639_2 = 'sin'; $si->country_code = 'lk'; $si->wp_locale = 'si_LK'; $si->slug = 'si'; $si->google_code = 'si'; $si->facebook_locale = 'si_LK'; $si->alphabet = 'sinhala'; $sk = new GP_Locale(); $sk->english_name = 'Slovak'; $sk->native_name = 'Slovenčina'; $sk->lang_code_iso_639_1 = 'sk'; $sk->lang_code_iso_639_2 = 'slk'; $sk->country_code = 'sk'; $sk->slug = 'sk'; $sk->wp_locale = 'sk_SK'; $sk->nplurals = 3; $sk->plural_expression = '(n == 1) ? 0 : ((n >= 2 && n <= 4) ? 1 : 2)'; $sk->google_code = 'sk'; $sk->facebook_locale = 'sk_SK'; $skr = new GP_Locale(); $skr->english_name = 'Saraiki'; $skr->native_name = 'سرائیکی'; $skr->lang_code_iso_639_3 = 'skr'; $skr->country_code = 'pk'; $skr->wp_locale = 'skr'; $skr->slug = 'skr'; $skr->text_direction = 'rtl'; $skr->alphabet = 'saraiki'; $sl = new GP_Locale(); $sl->english_name = 'Slovenian'; $sl->native_name = 'Slovenščina'; $sl->lang_code_iso_639_1 = 'sl'; $sl->lang_code_iso_639_2 = 'slv'; $sl->country_code = 'si'; $sl->wp_locale = 'sl_SI'; $sl->slug = 'sl'; $sl->nplurals = 4; $sl->plural_expression = '(n % 100 == 1) ? 0 : ((n % 100 == 2) ? 1 : ((n % 100 == 3 || n % 100 == 4) ? 2 : 3))'; $sl->google_code = 'sl'; $sl->facebook_locale = 'sl_SI'; $sna = new GP_Locale(); $sna->english_name = 'Shona'; $sna->native_name = 'ChiShona'; $sna->lang_code_iso_639_1 = 'sn'; $sna->lang_code_iso_639_3 = 'sna'; $sna->country_code = 'zw'; $sna->wp_locale = 'sna'; $sna->slug = 'sna'; $snd = new GP_Locale(); $snd->english_name = 'Sindhi'; $snd->native_name = 'سنڌي'; $snd->lang_code_iso_639_1 = 'sd'; $snd->lang_code_iso_639_2 = 'snd'; $snd->lang_code_iso_639_3 = 'snd'; $snd->country_code = 'pk'; $snd->wp_locale = 'snd'; $snd->slug = 'snd'; $snd->text_direction = 'rtl'; $snd->alphabet = 'arabic'; $so = new GP_Locale(); $so->english_name = 'Somali'; $so->native_name = 'Afsoomaali'; $so->lang_code_iso_639_1 = 'so'; $so->lang_code_iso_639_2 = 'som'; $so->lang_code_iso_639_3 = 'som'; $so->country_code = 'so'; $so->wp_locale = 'so_SO'; $so->slug = 'so'; $so->google_code = 'so'; $so->facebook_locale = 'so_SO'; $sq = new GP_Locale(); $sq->english_name = 'Albanian'; $sq->native_name = 'Shqip'; $sq->lang_code_iso_639_1 = 'sq'; $sq->lang_code_iso_639_2 = 'sqi'; $sq->wp_locale = 'sq'; $sq->country_code = 'al'; $sq->slug = 'sq'; $sq->google_code = 'sq'; $sq->facebook_locale = 'sq_AL'; $sq_xk = new GP_Locale(); $sq_xk->english_name = 'Shqip (Kosovo)'; $sq_xk->native_name = 'Për Kosovën Shqip'; $sq_xk->lang_code_iso_639_1 = 'sq'; $sq_xk->country_code = 'xk'; // Temporary country code until Kosovo is assigned an ISO code. $sq_xk->wp_locale = 'sq_XK'; $sq_xk->slug = 'sq-xk'; $sr = new GP_Locale(); $sr->english_name = 'Serbian'; $sr->native_name = 'Српски језик'; $sr->lang_code_iso_639_1 = 'sr'; $sr->lang_code_iso_639_2 = 'srp'; $sr->country_code = 'rs'; $sr->wp_locale = 'sr_RS'; $sr->slug = 'sr'; $sr->nplurals = 3; $sr->plural_expression = '(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2)'; $sr->google_code = 'sr'; $sr->facebook_locale = 'sr_RS'; $sr->alphabet = 'cyrillic'; $srd = new GP_Locale(); $srd->english_name = 'Sardinian'; $srd->native_name = 'Sardu'; $srd->lang_code_iso_639_1 = 'sc'; $srd->lang_code_iso_639_2 = 'srd'; $srd->country_code = 'it'; $srd->wp_locale = 'srd'; $srd->slug = 'srd'; $srd->facebook_locale = 'sc_IT'; $ssw = new GP_Locale(); $ssw->english_name = 'Swati'; $ssw->native_name = 'SiSwati'; $ssw->lang_code_iso_639_1 = 'ss'; $ssw->lang_code_iso_639_2 = 'ssw'; $ssw->lang_code_iso_639_3 = 'ssw'; $ssw->country_code = 'sz'; $ssw->wp_locale = 'ssw'; $ssw->slug = 'ssw'; $su = new GP_Locale(); $su->english_name = 'Sundanese'; $su->native_name = 'Basa Sunda'; $su->lang_code_iso_639_1 = 'su'; $su->lang_code_iso_639_2 = 'sun'; $su->country_code = 'id'; $su->wp_locale = 'su_ID'; $su->slug = 'su'; $su->nplurals = 1; $su->plural_expression = '0'; $su->google_code = 'su'; $sv = new GP_Locale(); $sv->english_name = 'Swedish'; $sv->native_name = 'Svenska'; $sv->lang_code_iso_639_1 = 'sv'; $sv->lang_code_iso_639_2 = 'swe'; $sv->country_code = 'se'; $sv->wp_locale = 'sv_SE'; $sv->slug = 'sv'; $sv->google_code = 'sv'; $sv->facebook_locale = 'sv_SE'; $sw = new GP_Locale(); $sw->english_name = 'Swahili'; $sw->native_name = 'Kiswahili'; $sw->lang_code_iso_639_1 = 'sw'; $sw->lang_code_iso_639_2 = 'swa'; $sw->wp_locale = 'sw'; $sw->slug = 'sw'; $sw->google_code = 'sw'; $sw->facebook_locale = 'sw_KE'; $syr = new GP_Locale(); $syr->english_name = 'Syriac'; $syr->native_name = 'Syriac'; $syr->lang_code_iso_639_3 = 'syr'; $syr->country_code = 'iq'; $syr->wp_locale = 'syr'; $syr->slug = 'syr'; $syr->alphabet = 'syriac'; $szl = new GP_Locale(); $szl->english_name = 'Silesian'; $szl->native_name = 'Ślōnskŏ gŏdka'; $szl->lang_code_iso_639_3 = 'szl'; $szl->country_code = 'pl'; $szl->wp_locale = 'szl'; $szl->slug = 'szl'; $szl->nplurals = 3; $szl->plural_expression = '(n==1 ? 0 : n%10>=2 && n%10<=4 && n%100==20 ? 1 : 2)'; $szl->facebook_locale = 'sz_PL'; $ta = new GP_Locale(); $ta->english_name = 'Tamil'; $ta->native_name = 'தமிழ்'; $ta->lang_code_iso_639_1 = 'ta'; $ta->lang_code_iso_639_2 = 'tam'; $ta->country_code = 'in'; $ta->wp_locale = 'ta_IN'; $ta->slug = 'ta'; $ta->google_code = 'ta'; $ta->facebook_locale = 'ta_IN'; $ta->alphabet = 'tamil'; $ta_lk = new GP_Locale(); $ta_lk->english_name = 'Tamil (Sri Lanka)'; $ta_lk->native_name = 'தமிழ்'; $ta_lk->lang_code_iso_639_1 = 'ta'; $ta_lk->lang_code_iso_639_2 = 'tam'; $ta_lk->country_code = 'lk'; $ta_lk->wp_locale = 'ta_LK'; $ta_lk->slug = 'ta-lk'; $ta_lk->google_code = 'ta'; $ta_lk->alphabet = 'tamil'; $tah = new GP_Locale(); $tah->english_name = 'Tahitian'; $tah->native_name = 'Reo Tahiti'; $tah->lang_code_iso_639_1 = 'ty'; $tah->lang_code_iso_639_2 = 'tah'; $tah->lang_code_iso_639_3 = 'tah'; $tah->country_code = 'pf'; $tah->wp_locale = 'tah'; $tah->slug = 'tah'; $tah->nplurals = 2; $tah->plural_expression = 'n > 1'; $te = new GP_Locale(); $te->english_name = 'Telugu'; $te->native_name = 'తెలుగు'; $te->lang_code_iso_639_1 = 'te'; $te->lang_code_iso_639_2 = 'tel'; $te->wp_locale = 'te'; $te->slug = 'te'; $te->google_code = 'te'; $te->facebook_locale = 'te_IN'; $te->alphabet = 'telugu'; $tg = new GP_Locale(); $tg->english_name = 'Tajik'; $tg->native_name = 'Тоҷикӣ'; $tg->lang_code_iso_639_1 = 'tg'; $tg->lang_code_iso_639_2 = 'tgk'; $tg->country_code = 'tj'; $tg->wp_locale = 'tg'; $tg->slug = 'tg'; $tg->google_code = 'tg'; $tg->facebook_locale = 'tg_TJ'; $tg->alphabet = 'cyrillic'; $th = new GP_Locale(); $th->english_name = 'Thai'; $th->native_name = 'ไทย'; $th->lang_code_iso_639_1 = 'th'; $th->lang_code_iso_639_2 = 'tha'; $th->wp_locale = 'th'; $th->slug = 'th'; $th->nplurals = 1; $th->plural_expression = '0'; $th->google_code = 'th'; $th->facebook_locale = 'th_TH'; $th->alphabet = 'thai'; $th->word_count_type = 'characters_excluding_spaces'; $tir = new GP_Locale(); $tir->english_name = 'Tigrinya'; $tir->native_name = 'ትግርኛ'; $tir->lang_code_iso_639_1 = 'ti'; $tir->lang_code_iso_639_2 = 'tir'; $tir->country_code = 'er'; $tir->wp_locale = 'tir'; $tir->slug = 'tir'; $tir->nplurals = 1; $tir->plural_expression = '0'; $tir->alphabet = 'geez'; $tlh = new GP_Locale(); $tlh->english_name = 'Klingon'; $tlh->native_name = 'TlhIngan'; $tlh->lang_code_iso_639_2 = 'tlh'; $tlh->slug = 'tlh'; $tlh->nplurals = 1; $tlh->plural_expression = '0'; $tlh->facebook_locale = 'tl_ST'; $tl = new GP_Locale(); $tl->english_name = 'Tagalog'; $tl->native_name = 'Tagalog'; $tl->lang_code_iso_639_1 = 'tl'; $tl->lang_code_iso_639_2 = 'tgl'; $tl->country_code = 'ph'; $tl->wp_locale = 'tl'; $tl->slug = 'tl'; $tl->google_code = 'tl'; $tl->facebook_locale = 'tl_PH'; $tr = new GP_Locale(); $tr->english_name = 'Turkish'; $tr->native_name = 'Türkçe'; $tr->lang_code_iso_639_1 = 'tr'; $tr->lang_code_iso_639_2 = 'tur'; $tr->country_code = 'tr'; $tr->wp_locale = 'tr_TR'; $tr->slug = 'tr'; $tr->nplurals = 2; $tr->plural_expression = 'n > 1'; $tr->google_code = 'tr'; $tr->facebook_locale = 'tr_TR'; $tt_ru = new GP_Locale(); $tt_ru->english_name = 'Tatar'; $tt_ru->native_name = 'Татар теле'; $tt_ru->lang_code_iso_639_1 = 'tt'; $tt_ru->lang_code_iso_639_2 = 'tat'; $tt_ru->country_code = 'ru'; $tt_ru->wp_locale = 'tt_RU'; $tt_ru->slug = 'tt'; $tt_ru->nplurals = 1; $tt_ru->plural_expression = '0'; $tt_ru->facebook_locale = 'tt_RU'; $tt_ru->alphabet = 'cyrillic'; $tuk = new GP_Locale(); $tuk->english_name = 'Turkmen'; $tuk->native_name = 'Türkmençe'; $tuk->lang_code_iso_639_1 = 'tk'; $tuk->lang_code_iso_639_2 = 'tuk'; $tuk->country_code = 'tm'; $tuk->wp_locale = 'tuk'; $tuk->slug = 'tuk'; $tuk->nplurals = 2; $tuk->plural_expression = 'n > 1'; $tuk->facebook_locale = 'tk_TM'; $twd = new GP_Locale(); $twd->english_name = 'Tweants'; $twd->native_name = 'Twents'; $twd->lang_code_iso_639_3 = 'twd'; $twd->country_code = 'nl'; $twd->wp_locale = 'twd'; $twd->slug = 'twd'; $tzm = new GP_Locale(); $tzm->english_name = 'Tamazight (Central Atlas)'; $tzm->native_name = 'ⵜⴰⵎⴰⵣⵉⵖⵜ'; $tzm->lang_code_iso_639_2 = 'tzm'; $tzm->country_code = 'ma'; $tzm->wp_locale = 'tzm'; $tzm->slug = 'tzm'; $tzm->nplurals = 2; $tzm->plural_expression = 'n > 1'; $tzm->alphabet = 'tifinagh'; $udm = new GP_Locale(); $udm->english_name = 'Udmurt'; $udm->native_name = 'Удмурт кыл'; $udm->lang_code_iso_639_2 = 'udm'; $udm->slug = 'udm'; $udm->alphabet = 'cyrillic'; $ug = new GP_Locale(); $ug->english_name = 'Uighur'; $ug->native_name = 'ئۇيغۇرچە'; $ug->lang_code_iso_639_1 = 'ug'; $ug->lang_code_iso_639_2 = 'uig'; $ug->country_code = 'cn'; $ug->wp_locale = 'ug_CN'; $ug->slug = 'ug'; $ug->text_direction = 'rtl'; $ug->alphabet = 'uyghur'; $uk = new GP_Locale(); $uk->english_name = 'Ukrainian'; $uk->native_name = 'Українська'; $uk->lang_code_iso_639_1 = 'uk'; $uk->lang_code_iso_639_2 = 'ukr'; $uk->country_code = 'ua'; $uk->wp_locale = 'uk'; $uk->slug = 'uk'; $uk->nplurals = 3; $uk->plural_expression = '(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2)'; $uk->google_code = 'uk'; $uk->facebook_locale = 'uk_UA'; $uk->alphabet = 'cyrillic'; $ur = new GP_Locale(); $ur->english_name = 'Urdu'; $ur->native_name = 'اردو'; $ur->lang_code_iso_639_1 = 'ur'; $ur->lang_code_iso_639_2 = 'urd'; $ur->country_code = 'pk'; $ur->wp_locale = 'ur'; $ur->slug = 'ur'; $ur->text_direction = 'rtl'; $ur->google_code = 'ur'; $ur->facebook_locale = 'ur_PK'; $ur->alphabet = 'persian'; $uz = new GP_Locale(); $uz->english_name = 'Uzbek'; $uz->native_name = 'O‘zbekcha'; $uz->lang_code_iso_639_1 = 'uz'; $uz->lang_code_iso_639_2 = 'uzb'; $uz->country_code = 'uz'; $uz->wp_locale = 'uz_UZ'; $uz->slug = 'uz'; $uz->nplurals = 1; $uz->plural_expression = '0'; $uz->google_code = 'uz'; $uz->facebook_locale = 'uz_UZ'; $vec = new GP_Locale(); $vec->english_name = 'Venetian'; $vec->native_name = 'Vèneto'; $vec->lang_code_iso_639_2 = 'roa'; $vec->lang_code_iso_639_3 = 'vec'; $vec->country_code = 'it'; $vec->slug = 'vec'; $vec->wp_locale = 'vec'; $vi = new GP_Locale(); $vi->english_name = 'Vietnamese'; $vi->native_name = 'Tiếng Việt'; $vi->lang_code_iso_639_1 = 'vi'; $vi->lang_code_iso_639_2 = 'vie'; $vi->country_code = 'vn'; $vi->wp_locale = 'vi'; $vi->slug = 'vi'; $vi->nplurals = 1; $vi->plural_expression = '0'; $vi->google_code = 'vi'; $vi->facebook_locale = 'vi_VN'; $wa = new GP_Locale(); $wa->english_name = 'Walloon'; $wa->native_name = 'Walon'; $wa->lang_code_iso_639_1 = 'wa'; $wa->lang_code_iso_639_2 = 'wln'; $wa->country_code = 'be'; $wa->slug = 'wa'; $wol = new GP_Locale(); $wol->english_name = 'Wolof'; $wol->native_name = 'Wolof'; $wol->lang_code_iso_639_1 = 'wo'; $wol->lang_code_iso_639_2 = 'wol'; $wol->lang_code_iso_639_3 = 'wol'; $wol->country_code = 'sn'; $wol->wp_locale = 'wol'; $wol->slug = 'wol'; $wol->nplurals = 1; $wol->plural_expression = '0'; $xho = new GP_Locale(); $xho->english_name = 'Xhosa'; $xho->native_name = 'isiXhosa'; $xho->lang_code_iso_639_1 = 'xh'; $xho->lang_code_iso_639_2 = 'xho'; $xho->lang_code_iso_639_3 = 'xho'; $xho->country_code = 'za'; $xho->wp_locale = 'xho'; $xho->slug = 'xho'; $xho->google_code = 'xh'; $xho->facebook_locale = 'xh_ZA'; $xmf = new GP_Locale(); $xmf->english_name = 'Mingrelian'; $xmf->native_name = 'მარგალური ნინა'; $xmf->lang_code_iso_639_3 = 'xmf'; $xmf->country_code = 'ge'; $xmf->slug = 'xmf'; $xmf->alphabet = 'georgian'; $yi = new GP_Locale(); $yi->english_name = 'Yiddish'; $yi->native_name = 'ייִדיש'; $yi->lang_code_iso_639_1 = 'yi'; $yi->lang_code_iso_639_2 = 'yid'; $yi->slug = 'yi'; $yi->text_direction = 'rtl'; $yi->google_code = 'yi'; $yi->alphabet = 'hebrew'; $yor = new GP_Locale(); $yor->english_name = 'Yoruba'; $yor->native_name = 'Yorùbá'; $yor->lang_code_iso_639_1 = 'yo'; $yor->lang_code_iso_639_2 = 'yor'; $yor->lang_code_iso_639_3 = 'yor'; $yor->country_code = 'ng'; $yor->wp_locale = 'yor'; $yor->slug = 'yor'; $yor->google_code = 'yo'; $yor->facebook_locale = 'yo_NG'; $zgh = new GP_Locale(); $zgh->english_name = 'Tamazight'; $zgh->native_name = 'ⵜⴰⵎⴰⵣⵉⵖⵜ'; $zgh->lang_code_iso_639_2 = 'zgh'; $zgh->lang_code_iso_639_3 = 'zgh'; $zgh->country_code = 'ma'; $zgh->wp_locale = 'zgh'; $zgh->slug = 'zgh'; $zgh->nplurals = 2; $zgh->plural_expression = 'n >= 2 && (n < 11 || n > 99)'; $zgh->alphabet = 'tifinagh'; $zh = new GP_Locale(); $zh->english_name = 'Chinese'; $zh->native_name = '中文'; $zh->lang_code_iso_639_1 = 'zh'; $zh->lang_code_iso_639_2 = 'zho'; $zh->slug = 'zh'; $zh->nplurals = 1; $zh->plural_expression = '0'; $zh->alphabet = 'hanyu'; $zh_cn = new GP_Locale(); $zh_cn->english_name = 'Chinese (China)'; $zh_cn->native_name = '简体中文'; $zh_cn->lang_code_iso_639_1 = 'zh'; $zh_cn->lang_code_iso_639_2 = 'zho'; $zh_cn->country_code = 'cn'; $zh_cn->wp_locale = 'zh_CN'; $zh_cn->slug = 'zh-cn'; $zh_cn->nplurals = 1; $zh_cn->plural_expression = '0'; $zh_cn->google_code = 'zh-CN'; $zh_cn->facebook_locale = 'zh_CN'; $zh_cn->alphabet = 'simplified-chinese'; $zh_cn->word_count_type = 'characters_excluding_spaces'; $zh_hk = new GP_Locale(); $zh_hk->english_name = 'Chinese (Hong Kong)'; $zh_hk->native_name = '香港中文'; $zh_hk->lang_code_iso_639_1 = 'zh'; $zh_hk->lang_code_iso_639_2 = 'zho'; $zh_hk->country_code = 'hk'; $zh_hk->wp_locale = 'zh_HK'; $zh_hk->slug = 'zh-hk'; $zh_hk->nplurals = 1; $zh_hk->plural_expression = '0'; $zh_hk->facebook_locale = 'zh_HK'; $zh_hk->alphabet = 'simplified-chinese'; $zh_hk->word_count_type = 'characters_excluding_spaces'; $zh_sg = new GP_Locale(); $zh_sg->english_name = 'Chinese (Singapore)'; $zh_sg->native_name = '中文'; $zh_sg->lang_code_iso_639_1 = 'zh'; $zh_sg->lang_code_iso_639_2 = 'zho'; $zh_sg->country_code = 'sg'; $zh_sg->wp_locale = 'zh_SG'; $zh_sg->slug = 'zh-sg'; $zh_sg->nplurals = 1; $zh_sg->plural_expression = '0'; $zh_sg->alphabet = 'hanyu'; $zh_sg->word_count_type = 'characters_excluding_spaces'; $zh_tw = new GP_Locale(); $zh_tw->english_name = 'Chinese (Taiwan)'; $zh_tw->native_name = '繁體中文'; $zh_tw->lang_code_iso_639_1 = 'zh'; $zh_tw->lang_code_iso_639_2 = 'zho'; $zh_tw->country_code = 'tw'; $zh_tw->slug = 'zh-tw'; $zh_tw->wp_locale = 'zh_TW'; $zh_tw->nplurals = 1; $zh_tw->plural_expression = '0'; $zh_tw->google_code = 'zh-TW'; $zh_tw->facebook_locale = 'zh_TW'; $zh_tw->alphabet = 'hanyu'; $zh_tw->word_count_type = 'characters_excluding_spaces'; $zul = new GP_Locale(); $zul->english_name = 'Zulu'; $zul->native_name = 'isiZulu'; $zul->lang_code_iso_639_1 = 'zu'; $zul->lang_code_iso_639_2 = 'zul'; $zul->lang_code_iso_639_3 = 'zul'; $zul->country_code = 'za'; $zul->wp_locale = 'zul'; $zul->slug = 'zul'; $zul->google_code = 'zu'; $def_vars = get_defined_vars(); if ( function_exists( 'apply_filters' ) ) { /** * Fires after the locales have been defined but before they have been assigned to the object property. * * @since 3.0.0 * * @param array $def_vars The array of locale objects. * * @return array The updated array of locale objects. */ $def_vars = apply_filters( 'gp_locale_definitions_array', $def_vars ); } foreach ( $def_vars as $locale ) { $this->locales[ $locale->slug ] = $locale; } } public static function &instance() { if ( ! isset( $GLOBALS['gp_locales'] ) ) $GLOBALS['gp_locales'] = new GP_Locales; return $GLOBALS['gp_locales']; } public static function locales() { $instance = GP_Locales::instance(); return $instance->locales; } public static function exists( $slug ) { $instance = GP_Locales::instance(); return isset( $instance->locales[ $slug ] ); } public static function by_slug( $slug ) { $instance = GP_Locales::instance(); return isset( $instance->locales[ $slug ] ) ? $instance->locales[ $slug ] : null; } public static function by_field( $field_name, $field_value ) { $instance = GP_Locales::instance(); $result = false; foreach ( $instance->locales() as $locale ) { if ( isset( $locale->$field_name ) && $locale->$field_name == $field_value ) { $result = $locale; break; } } return $result; } } endif;