Skip to content
Snippets Groups Projects
Commit 3d1186a8 authored by agata's avatar agata
Browse files

[auto] plugin: bogo 3.5

parent 8319bc7b
Branches
Tags
No related merge requests found
Showing
with 800 additions and 830 deletions
...@@ -44,26 +44,10 @@ function bogo_admin_enqueue_scripts( $hook_suffix ) { ...@@ -44,26 +44,10 @@ function bogo_admin_enqueue_scripts( $hook_suffix ) {
'orderby' => 'value', 'orderby' => 'value',
) ); ) );
$add_translation_l10n = array();
foreach ( $available_languages as $locale => $lang ) {
$add_translation_l10n[$locale] = sprintf(
/* translators: %s: language name */
__( 'Add %s Translation', 'bogo' ),
$lang
);
}
$local_args = array( $local_args = array(
'l10n' => array( 'l10n' => array(
/* translators: accessibility text */ /* translators: accessibility text */
'targetBlank' => __( '(opens in a new window)', 'bogo' ), 'targetBlank' => __( '(opens in a new window)', 'bogo' ),
'language' => __( 'Language', 'bogo' ),
'none' => __( 'None', 'bogo' ),
'translations' => __( 'Translations', 'bogo' ),
'addTranslation' => $add_translation_l10n,
'noticePostCreation' => __( "Translation post created.", 'bogo' ),
'editPost' => __( 'Edit Post', 'bogo' ),
'saveAlert' => __( "The changes you made will be lost if you navigate away from this page.", 'bogo' ), 'saveAlert' => __( "The changes you made will be lost if you navigate away from this page.", 'bogo' ),
), ),
'apiSettings' => array( 'apiSettings' => array(
...@@ -128,15 +112,23 @@ function bogo_admin_enqueue_scripts( $hook_suffix ) { ...@@ -128,15 +112,23 @@ function bogo_admin_enqueue_scripts( $hook_suffix ) {
add_action( 'admin_menu', 'bogo_admin_menu', 10, 0 ); add_action( 'admin_menu', 'bogo_admin_menu', 10, 0 );
function bogo_admin_menu() { function bogo_admin_menu() {
add_menu_page( __( 'Languages', 'bogo' ), __( 'Languages', 'bogo' ), add_menu_page(
'bogo_manage_language_packs', 'bogo', 'bogo_tools_page', __( 'Languages', 'bogo' ),
'dashicons-translation', 73 // between Users (70) and Tools (75) __( 'Languages', 'bogo' ),
'bogo_manage_language_packs',
'bogo',
'bogo_tools_page',
'dashicons-translation',
73 // between Users (70) and Tools (75)
); );
$tools = add_submenu_page( 'bogo', $tools = add_submenu_page(
'bogo',
__( 'Language Packs', 'bogo' ), __( 'Language Packs', 'bogo' ),
__( 'Language Packs', 'bogo' ), __( 'Language Packs', 'bogo' ),
'bogo_manage_language_packs', 'bogo', 'bogo_tools_page' 'bogo_manage_language_packs',
'bogo',
'bogo_tools_page'
); );
add_action( 'load-' . $tools, 'bogo_load_tools_page', 10, 0 ); add_action( 'load-' . $tools, 'bogo_load_tools_page', 10, 0 );
...@@ -147,21 +139,28 @@ function bogo_admin_menu() { ...@@ -147,21 +139,28 @@ function bogo_admin_menu() {
) ); ) );
if ( 0 < count( $available_locales ) ) { if ( 0 < count( $available_locales ) ) {
$texts = add_submenu_page( 'bogo', $texts = add_submenu_page(
'bogo',
__( 'Terms Translation', 'bogo' ), __( 'Terms Translation', 'bogo' ),
__( 'Terms Translation', 'bogo' ), __( 'Terms Translation', 'bogo' ),
'bogo_edit_terms_translation', 'bogo-texts', 'bogo_texts_page' 'bogo_edit_terms_translation',
'bogo-texts',
'bogo_texts_page'
); );
add_action( 'load-' . $texts, 'bogo_load_texts_page', 10, 0 ); add_action( 'load-' . $texts, 'bogo_load_texts_page', 10, 0 );
} }
} }
add_filter( 'set-screen-option', 'bogo_set_screen_options', 10, 3 ); add_filter(
'set_screen_option_bogo_texts_per_page',
'bogo_set_screen_options',
10, 3
);
function bogo_set_screen_options( $result, $option, $value ) { function bogo_set_screen_options( $result, $option, $value ) {
$bogo_screens = array( $bogo_screens = array(
'languages_page_bogo_texts_per_page', 'bogo_texts_per_page',
); );
if ( in_array( $option, $bogo_screens ) ) { if ( in_array( $option, $bogo_screens ) ) {
...@@ -407,8 +406,8 @@ function bogo_load_texts_page() { ...@@ -407,8 +406,8 @@ function bogo_load_texts_page() {
); );
add_screen_option( 'per_page', array( add_screen_option( 'per_page', array(
'label' => __( 'Items', 'bogo' ),
'default' => 20, 'default' => 20,
'option' => 'bogo_texts_per_page',
) ); ) );
} }
} }
......
...@@ -272,6 +272,9 @@ function bogo_l10n_meta_box( $post ) { ...@@ -272,6 +272,9 @@ function bogo_l10n_meta_box( $post ) {
echo ' [' . $lang . ']'; echo ' [' . $lang . ']';
echo '</li>'; echo '</li>';
// make it unavailable for select options
unset( $available_languages[$locale] );
} }
echo '</ul>'; echo '</ul>';
......
...@@ -54,8 +54,7 @@ class Bogo_Terms_Translation_List_Table extends WP_List_Table { ...@@ -54,8 +54,7 @@ class Bogo_Terms_Translation_List_Table extends WP_List_Table {
$items = array_filter( $items ); $items = array_filter( $items );
$items = array_values( $items ); $items = array_values( $items );
$per_page = $this->get_items_per_page( $per_page = $this->get_items_per_page( 'bogo_texts_per_page' );
'languages_page_bogo_texts_per_page' );
$offset = ( $this->get_pagenum() - 1 ) * $per_page; $offset = ( $this->get_pagenum() - 1 ) * $per_page;
$this->items = array_slice( $items, $offset, $per_page ); $this->items = array_slice( $items, $offset, $per_page );
......
...@@ -7,10 +7,10 @@ Author: Takayuki Miyoshi ...@@ -7,10 +7,10 @@ Author: Takayuki Miyoshi
Author URI: https://ideasilo.wordpress.com/ Author URI: https://ideasilo.wordpress.com/
Text Domain: bogo Text Domain: bogo
Domain Path: /languages/ Domain Path: /languages/
Version: 3.3.2 Version: 3.5
*/ */
define( 'BOGO_VERSION', '3.3.2' ); define( 'BOGO_VERSION', '3.5' );
define( 'BOGO_PLUGIN', __FILE__ ); define( 'BOGO_PLUGIN', __FILE__ );
...@@ -33,21 +33,12 @@ require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php'; ...@@ -33,21 +33,12 @@ require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php';
require_once BOGO_PLUGIN_DIR . '/includes/query.php'; require_once BOGO_PLUGIN_DIR . '/includes/query.php';
require_once BOGO_PLUGIN_DIR . '/includes/flags.php'; require_once BOGO_PLUGIN_DIR . '/includes/flags.php';
require_once BOGO_PLUGIN_DIR . '/includes/rest-api.php'; require_once BOGO_PLUGIN_DIR . '/includes/rest-api.php';
require_once BOGO_PLUGIN_DIR . '/includes/block-editor.php'; require_once BOGO_PLUGIN_DIR . '/includes/block-editor/block-editor.php';
if ( is_admin() ) { if ( is_admin() ) {
require_once BOGO_PLUGIN_DIR . '/admin/admin.php'; require_once BOGO_PLUGIN_DIR . '/admin/admin.php';
} }
add_action( 'plugins_loaded', 'bogo_plugins_loaded', 10, 0 );
function bogo_plugins_loaded() {
load_plugin_textdomain( 'bogo',
false,
'bogo/languages'
);
}
add_action( 'init', 'bogo_init', 10, 0 ); add_action( 'init', 'bogo_init', 10, 0 );
function bogo_init() { function bogo_init() {
...@@ -55,6 +46,21 @@ function bogo_init() { ...@@ -55,6 +46,21 @@ function bogo_init() {
Bogo_POMO::import( determine_locale() ); Bogo_POMO::import( determine_locale() );
} }
add_filter( 'pre_determine_locale', 'bogo_pre_determine_locale', 10, 1 );
function bogo_pre_determine_locale( $locale ) {
if ( ! empty( $_GET['filter_action'] ) ) {
return $locale;
}
if ( isset( $_GET['lang'] )
and $closest = bogo_get_closest_locale( $_GET['lang'] ) ) {
$locale = $closest;
}
return $locale;
}
add_filter( 'locale', 'bogo_locale', 10, 1 ); add_filter( 'locale', 'bogo_locale', 10, 1 );
function bogo_locale( $locale ) { function bogo_locale( $locale ) {
......
<?php
add_action(
'enqueue_block_editor_assets',
'bogo_init_block_editor_assets',
10, 0
);
function bogo_init_block_editor_assets() {
$assets = array();
$asset_file = path_join(
BOGO_PLUGIN_DIR,
'includes/block-editor/index.asset.php'
);
if ( file_exists( $asset_file ) ) {
$assets = include( $asset_file );
}
$assets = wp_parse_args( $assets, array(
'src' => plugins_url(
'includes/block-editor/index.js',
BOGO_PLUGIN_BASENAME
),
'dependencies' => array(
'wp-components',
'wp-data',
'wp-edit-post',
'wp-element',
'wp-plugins',
'wp-i18n',
),
'version' => BOGO_VERSION,
) );
wp_enqueue_script(
'bogo-block-editor',
$assets['src'],
$assets['dependencies'],
$assets['version']
);
wp_set_script_translations(
'bogo-block-editor',
'bogo'
);
}
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=15)}([function(e,t){e.exports=window.wp.element},function(e,t){e.exports=window.wp.i18n},function(e,t){e.exports=window.wp.components},function(e,t){e.exports=window.wp.url},function(e,t){e.exports=window.wp.apiFetch},function(e,t,n){var r=n(10),o=n(11),c=n(12),a=n(14);e.exports=function(e,t){return r(e)||o(e,t)||c(e,t)||a()}},function(e,t){e.exports=window.wp.data},function(e,t){e.exports=window.wp.plugins},function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(e,t){e.exports=window.wp.editPost},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var n=[],_n=!0,r=!1,o=void 0;try{for(var c,a=e[Symbol.iterator]();!(_n=(c=a.next()).done)&&(n.push(c.value),!t||n.length!==t);_n=!0);}catch(e){r=!0,o=e}finally{try{_n||null==a.return||a.return()}finally{if(r)throw o}}return n}}},function(e,t,n){var r=n(13);e.exports=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}},function(e,t,n){"use strict";n.r(t);var r=n(7),o=n(3),c=n(4),a=n.n(c),l=n(8),i=n.n(l),u=n(5),s=n.n(u),b=n(0),f=n(9),p=n(2),g=n(6),O=n(1);function j(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?j(Object(n),!0).forEach((function(t){i()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):j(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var m=function(e){return bogo.availableLanguages[e]?bogo.availableLanguages[e]:e};Object(r.registerPlugin)("bogo-language-panel",{render:function(){var e=Object(g.useSelect)((function(e){return Object.assign({},e("core/editor").getCurrentPost(),bogo.currentPost)}));if(-1==bogo.localizablePostTypes.indexOf(e.type))return Object(b.createElement)(b.Fragment,null);var t=Object(b.useState)(e.translations),n=s()(t,2),r=n[0],o=n[1];return Object(b.createElement)(f.PluginDocumentSettingPanel,{name:"bogo-language-panel",title:Object(O.__)("Language","bogo"),className:"bogo-language-panel"},Object(b.createElement)((function(){return Object(b.createElement)(p.PanelRow,null,Object(b.createElement)("span",null,Object(O.__)("Language","bogo")),Object(b.createElement)("div",null,m(e.locale)))}),null),Object(b.createElement)((function(){var e=[];return Object.entries(r).forEach((function(t){var n=s()(t,2),r=n[0],o=n[1];o.editLink&&o.postTitle?e.push(Object(b.createElement)("li",{key:r},Object(b.createElement)(p.ExternalLink,{href:o.editLink},o.postTitle),Object(b.createElement)("br",null),Object(b.createElement)("em",null,m(r)))):o.postTitle&&e.push(Object(b.createElement)("li",{key:r},o.postTitle,Object(b.createElement)("br",null),Object(b.createElement)("em",null,m(r))))})),Object(b.createElement)(p.PanelRow,null,Object(b.createElement)("span",null,Object(O.__)("Translations","bogo")),Object(b.createElement)((function(e){return e.listItems.length?Object(b.createElement)("ul",null,e.listItems):Object(b.createElement)("em",null,Object(O.__)("None","bogo"))}),{listItems:e}))}),null),Object(b.createElement)((function(){var t=[];return Object.entries(r).forEach((function(n){var c=s()(n,2),l=c[0],i=c[1];i.postId||t.push(Object(b.createElement)("li",{key:l},Object(b.createElement)(p.Button,{isDefault:!0,onClick:function(){var t,n;t=l,(n=d({},r))[t]={creating:!0},o(n),a()({path:"/bogo/v1/posts/".concat(e.id,"/translations/").concat(t),method:"POST"}).then((function(e){var n=d({},r);n[t]={postId:e[t].id,postTitle:e[t].title.raw,editLink:e[t].edit_link,creating:!1},o(n),Object(g.dispatch)("core/notices").createInfoNotice(Object(O.__)("Translation post created.","bogo"),{isDismissible:!0,type:"snackbar",speak:!0,actions:[{url:n[t].editLink,label:Object(O.__)("Edit Post","bogo")}]})}))}},Object(O.sprintf)(
/* translators: %s: Language name. */
Object(O.__)("Add %s translation","bogo"),m(l))),i.creating&&Object(b.createElement)(p.Spinner,null)))})),t.length<1||"auto-draft"==e.status?Object(b.createElement)(b.Fragment,null):Object(b.createElement)(p.PanelRow,null,Object(b.createElement)("ul",null,t))}),null))},icon:"translation"}),a.a.use((function(e,t){var n=bogo.currentPost.lang;return n&&("string"!=typeof e.url||Object(o.hasQueryArg)(e.url,"lang")||(e.url=Object(o.addQueryArgs)(e.url,{lang:n})),"string"!=typeof e.path||Object(o.hasQueryArg)(e.path,"lang")||(e.path=Object(o.addQueryArgs)(e.path,{lang:n}))),t(e,t)}))}]);
\ No newline at end of file
...@@ -35,6 +35,7 @@ function bogo_languages() { ...@@ -35,6 +35,7 @@ function bogo_languages() {
'de_AT' => __( 'German (Austria)', 'bogo' ), 'de_AT' => __( 'German (Austria)', 'bogo' ),
'de_CH' => __( 'German (Switzerland)', 'bogo' ), 'de_CH' => __( 'German (Switzerland)', 'bogo' ),
'de_CH_informal' => __( 'German (Switzerland) (Informal)', 'bogo' ), 'de_CH_informal' => __( 'German (Switzerland) (Informal)', 'bogo' ),
'dsb' => __( 'Lower Sorbian', 'bogo' ),
'dv' => __( 'Dhivehi', 'bogo' ), 'dv' => __( 'Dhivehi', 'bogo' ),
'dzo' => __( 'Dzongkha', 'bogo' ), 'dzo' => __( 'Dzongkha', 'bogo' ),
'el' => __( 'Greek', 'bogo' ), 'el' => __( 'Greek', 'bogo' ),
......
...@@ -7,12 +7,17 @@ add_action( 'init', ...@@ -7,12 +7,17 @@ add_action( 'init',
function() { function() {
$post_types = bogo_localizable_post_types(); $post_types = bogo_localizable_post_types();
$auth_callback = function ( $allowed, $meta_key, $object_id, $user_id ) {
return user_can( $user_id, 'edit_post', $object_id );
};
foreach ( $post_types as $post_type ) { foreach ( $post_types as $post_type ) {
register_post_meta( $post_type, register_post_meta( $post_type,
'_locale', '_locale',
array( array(
'type' => 'string', 'type' => 'string',
'single' => true, 'single' => true,
'auth_callback' => $auth_callback,
'show_in_rest' => true, 'show_in_rest' => true,
) )
); );
...@@ -22,6 +27,7 @@ add_action( 'init', ...@@ -22,6 +27,7 @@ add_action( 'init',
array( array(
'type' => 'string', 'type' => 'string',
'single' => true, 'single' => true,
'auth_callback' => $auth_callback,
'show_in_rest' => true, 'show_in_rest' => true,
) )
); );
...@@ -632,3 +638,18 @@ function bogo_truncate_post_slug( $slug, $length = 200 ) { ...@@ -632,3 +638,18 @@ function bogo_truncate_post_slug( $slug, $length = 200 ) {
return rtrim( $slug, '-' ); return rtrim( $slug, '-' );
} }
add_filter(
'wp_sitemaps_posts_query_args',
'bogo_sitemaps_posts_query_args',
10, 2
);
function bogo_sitemaps_posts_query_args( $args, $post_type ) {
if ( bogo_is_localizable_post_type( $post_type ) ) {
$args['bogo_suppress_locale_query'] = true;
}
return $args;
}
...@@ -8,6 +8,7 @@ function bogo_rest_api_init() { ...@@ -8,6 +8,7 @@ function bogo_rest_api_init() {
array( array(
'methods' => WP_REST_Server::READABLE, 'methods' => WP_REST_Server::READABLE,
'callback' => 'bogo_rest_languages', 'callback' => 'bogo_rest_languages',
'permission_callback' => '__return_true',
) )
); );
...@@ -16,6 +17,7 @@ function bogo_rest_api_init() { ...@@ -16,6 +17,7 @@ function bogo_rest_api_init() {
array( array(
'methods' => WP_REST_Server::READABLE, 'methods' => WP_REST_Server::READABLE,
'callback' => 'bogo_rest_post_translations', 'callback' => 'bogo_rest_post_translations',
'permission_callback' => '__return_true',
) )
); );
...@@ -26,6 +28,18 @@ function bogo_rest_api_init() { ...@@ -26,6 +28,18 @@ function bogo_rest_api_init() {
array( array(
'methods' => WP_REST_Server::CREATABLE, 'methods' => WP_REST_Server::CREATABLE,
'callback' => 'bogo_rest_create_post_translation', 'callback' => 'bogo_rest_create_post_translation',
'permission_callback' => function( WP_REST_Request $request ) {
$locale = $request->get_param( 'locale' );
if ( current_user_can( 'bogo_access_locale', $locale ) ) {
return true;
} else {
return new WP_Error( 'bogo_locale_forbidden',
__( "You are not allowed to access posts in the requested locale.", 'bogo' ),
array( 'status' => 403 )
);
}
},
) )
); );
} }
...@@ -178,13 +192,6 @@ function bogo_rest_create_post_translation( WP_REST_Request $request ) { ...@@ -178,13 +192,6 @@ function bogo_rest_create_post_translation( WP_REST_Request $request ) {
); );
} }
if ( ! current_user_can( 'bogo_access_locale', $locale ) ) {
return new WP_Error( 'bogo_locale_forbidden',
__( "You are not allowed to access posts in the requested locale.", 'bogo' ),
array( 'status' => 403 )
);
}
$new_post_id = bogo_duplicate_post( $post, $locale ); $new_post_id = bogo_duplicate_post( $post, $locale );
if ( ! $new_post_id ) { if ( ! $new_post_id ) {
......
...@@ -19,188 +19,6 @@ function bogo_add_rewrite_tags() { ...@@ -19,188 +19,6 @@ function bogo_add_rewrite_tags() {
} }
} }
add_filter( 'root_rewrite_rules', 'bogo_root_rewrite_rules', 10, 1 );
function bogo_root_rewrite_rules( $root_rewrite ) {
global $wp_rewrite;
$permastruct = trailingslashit( $wp_rewrite->root ) . '%lang%/';
$extra = bogo_generate_rewrite_rules( $permastruct, array(
'ep_mask' => EP_ROOT,
) );
return array_merge( $extra, $root_rewrite );
}
add_filter( 'post_rewrite_rules', 'bogo_post_rewrite_rules', 10, 1 );
function bogo_post_rewrite_rules( $post_rewrite ) {
global $wp_rewrite;
$permastruct = $wp_rewrite->permalink_structure;
// from wp-admin/includes/misc.php
$got_rewrite = apply_filters( 'got_rewrite',
apache_mod_loaded( 'mod_rewrite', true )
);
$got_url_rewrite = apply_filters( 'got_url_rewrite',
$got_rewrite || $GLOBALS['is_nginx'] || iis7_supports_permalinks()
);
if ( ! $got_url_rewrite ) {
$permastruct = preg_replace(
'#^/index\.php#', '/index.php/%lang%', $permastruct
);
} elseif ( is_multisite()
and ! is_subdomain_install()
and is_main_site() ) {
$permastruct = preg_replace(
'#^/blog#', '/%lang%/blog', $permastruct
);
} else {
$permastruct = preg_replace(
'#^/#', '/%lang%/', $permastruct
);
}
$extra = bogo_generate_rewrite_rules( $permastruct, array(
'ep_mask' => EP_PERMALINK,
'paged' => false,
) );
return array_merge( $extra, $post_rewrite );
}
add_filter( 'date_rewrite_rules', 'bogo_date_rewrite_rules', 10, 1 );
function bogo_date_rewrite_rules( $date_rewrite ) {
global $wp_rewrite;
$permastruct = $wp_rewrite->get_date_permastruct();
$permastruct = preg_replace(
'#^' . $wp_rewrite->front . '#',
'/%lang%' . $wp_rewrite->front,
$permastruct
);
$extra = bogo_generate_rewrite_rules( $permastruct, array(
'ep_mask' => EP_DATE,
) );
return array_merge( $extra, $date_rewrite );
}
add_filter( 'comments_rewrite_rules', 'bogo_comments_rewrite_rules', 10, 1 );
function bogo_comments_rewrite_rules( $comments_rewrite ) {
global $wp_rewrite;
$permastruct = trailingslashit( $wp_rewrite->root )
. '%lang%/' . $wp_rewrite->comments_base;
$extra = bogo_generate_rewrite_rules( $permastruct, array(
'ep_mask' => EP_COMMENTS,
'forcomments' => true,
'walk_dirs' => false,
) );
return array_merge( $extra, $comments_rewrite );
}
add_filter( 'search_rewrite_rules', 'bogo_search_rewrite_rules', 10, 1 );
function bogo_search_rewrite_rules( $search_rewrite ) {
global $wp_rewrite;
$permastruct = trailingslashit( $wp_rewrite->root ) . '%lang%/'
. $wp_rewrite->search_base . '/%search%';
$extra = bogo_generate_rewrite_rules( $permastruct, array(
'ep_mask' => EP_SEARCH,
) );
return array_merge( $extra, $search_rewrite );
}
add_filter( 'author_rewrite_rules', 'bogo_author_rewrite_rules', 10, 1 );
function bogo_author_rewrite_rules( $author_rewrite ) {
global $wp_rewrite;
$permastruct = $wp_rewrite->get_author_permastruct();
$permastruct = preg_replace(
'#^' . $wp_rewrite->front . '#',
'/%lang%' . $wp_rewrite->front,
$permastruct
);
$extra = bogo_generate_rewrite_rules( $permastruct, array(
'ep_mask' => EP_AUTHORS,
) );
return array_merge( $extra, $author_rewrite );
}
add_filter( 'page_rewrite_rules', 'bogo_page_rewrite_rules', 10, 1 );
function bogo_page_rewrite_rules( $page_rewrite ) {
global $wp_rewrite;
$wp_rewrite->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' );
$permastruct = trailingslashit( $wp_rewrite->root ) . '%lang%/%pagename%';
$extra = bogo_generate_rewrite_rules( $permastruct, array(
'ep_mask' => EP_PAGES,
'walk_dirs' => false,
) );
return array_merge( $extra, $page_rewrite );
}
add_filter( 'category_rewrite_rules', 'bogo_category_rewrite_rules', 10, 1 );
function bogo_category_rewrite_rules( $category_rewrite ) {
return bogo_taxonomy_rewrite_rules( $category_rewrite,
'category', EP_CATEGORIES
);
}
add_filter( 'post_tag_rewrite_rules', 'bogo_post_tag_rewrite_rules', 10, 1 );
function bogo_post_tag_rewrite_rules( $post_tag_rewrite ) {
return bogo_taxonomy_rewrite_rules( $post_tag_rewrite, 'post_tag', EP_TAGS );
}
add_filter( 'post_format_rewrite_rules',
'bogo_post_format_rewrite_rules',
10, 1
);
function bogo_post_format_rewrite_rules( $post_format_rewrite ) {
return bogo_taxonomy_rewrite_rules( $post_format_rewrite, 'post_format' );
}
function bogo_taxonomy_rewrite_rules( $taxonomy_rewrite, $taxonomy, $ep_mask = EP_NONE ) {
global $wp_rewrite;
$permastruct = $wp_rewrite->get_extra_permastruct( $taxonomy );
$permastruct = preg_replace(
'#^' . $wp_rewrite->front . '#',
'/%lang%' . $wp_rewrite->front,
$permastruct
);
$extra = bogo_generate_rewrite_rules( $permastruct, array(
'ep_mask' => $ep_mask,
) );
return array_merge( $extra, $taxonomy_rewrite );
}
add_filter( 'rewrite_rules_array', 'bogo_rewrite_rules_array', 10, 1 ); add_filter( 'rewrite_rules_array', 'bogo_rewrite_rules_array', 10, 1 );
...@@ -209,57 +27,21 @@ function bogo_rewrite_rules_array( $rules ) { ...@@ -209,57 +27,21 @@ function bogo_rewrite_rules_array( $rules ) {
$lang_regex = bogo_get_lang_regex(); $lang_regex = bogo_get_lang_regex();
// REST rewrite rules $extra_rules = array();
if ( function_exists( 'rest_get_url_prefix' ) ) { $localizable_post_types = bogo_localizable_post_types();
$rest_url_prefix = rest_get_url_prefix();
$extra_rules = array(
"^{$lang_regex}/{$rest_url_prefix}/?$"
=> 'index.php?lang=$matches[1]&rest_route=/',
"^{$lang_regex}/{$rest_url_prefix}/(.*)?"
=> 'index.php?lang=$matches[1]&rest_route=/$matches[2]',
);
$rules = $extra_rules + $rules;
}
$post_types = array_diff(
(array) bogo_localizable_post_types(),
get_post_types( array( '_builtin' => true ) )
);
if ( empty( $post_types ) ) {
return $rules;
}
foreach ( $post_types as $post_type ) {
if ( ! $post_type_obj = get_post_type_object( $post_type ) ) {
continue;
}
if ( false === $post_type_obj->rewrite ) { foreach ( $localizable_post_types as $post_type ) {
if ( ! $post_type_obj = get_post_type_object( $post_type )
or false === $post_type_obj->rewrite ) {
continue; continue;
} }
$permastruct = $wp_rewrite->get_extra_permastruct( $post_type ); $permastruct = $wp_rewrite->get_extra_permastruct( $post_type );
$permastruct = bogo_add_lang_to_permastruct( $permastruct );
if ( $post_type_obj->rewrite['with_front'] ) { $extra_rules += bogo_generate_rewrite_rules(
$permastruct = preg_replace( $permastruct,
'#^' . $wp_rewrite->front . '#', $post_type_obj->rewrite
'/%lang%' . $wp_rewrite->front,
$permastruct
);
} else {
$permastruct = preg_replace(
'#^' . $wp_rewrite->root . '#',
'/%lang%/' . $wp_rewrite->root,
$permastruct
);
}
$rules = array_merge(
bogo_generate_rewrite_rules( $permastruct, $post_type_obj->rewrite ),
$rules
); );
if ( $post_type_obj->has_archive ) { if ( $post_type_obj->has_archive ) {
...@@ -275,149 +57,242 @@ function bogo_rewrite_rules_array( $rules ) { ...@@ -275,149 +57,242 @@ function bogo_rewrite_rules_array( $rules ) {
$archive_slug = $wp_rewrite->root . $archive_slug; $archive_slug = $wp_rewrite->root . $archive_slug;
} }
$extra_rules = array( $extra_rules += array(
"{$lang_regex}/{$archive_slug}/?$" "{$lang_regex}/{$archive_slug}/?$"
=> 'index.php?lang=$matches[1]&post_type=' . $post_type, => 'index.php?lang=$matches[1]&post_type=' . $post_type,
); );
$rules = $extra_rules + $rules; if ( $post_type_obj->rewrite['feeds'] and $wp_rewrite->feeds ) {
if ( $post_type_obj->rewrite['feeds'] && $wp_rewrite->feeds ) {
$feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')'; $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
$extra_rules = array( $extra_rules += array(
"{$lang_regex}/{$archive_slug}/feed/$feeds/?$" "{$lang_regex}/{$archive_slug}/feed/$feeds/?$"
=> 'index.php?lang=$matches[1]&post_type=' . $post_type . '&feed=$matches[2]', => 'index.php?lang=$matches[1]&post_type=' . $post_type . '&feed=$matches[2]',
"{$lang_regex}/{$archive_slug}/$feeds/?$" "{$lang_regex}/{$archive_slug}/$feeds/?$"
=> 'index.php?lang=$matches[1]&post_type=' . $post_type . '&feed=$matches[2]', => 'index.php?lang=$matches[1]&post_type=' . $post_type . '&feed=$matches[2]',
); );
$rules = $extra_rules + $rules;
} }
if ( $post_type_obj->rewrite['pages'] ) { if ( $post_type_obj->rewrite['pages'] ) {
$extra_rules = array( $extra_rules += array(
"{$lang_regex}/{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$" => 'index.php?lang=$matches[1]&post_type=' . $post_type . '&paged=$matches[2]', "{$lang_regex}/{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$"
=> 'index.php?lang=$matches[1]&post_type=' . $post_type . '&paged=$matches[2]',
); );
$rules = $extra_rules + $rules;
} }
} }
}
foreach ( get_object_taxonomies( $post_type ) as $tax ) { $localizable_taxonomies = get_object_taxonomies(
if ( ! $tax_obj = get_taxonomy( $tax ) ) { $localizable_post_types,
continue; 'objects'
} );
if ( false === $tax_obj->rewrite ) { foreach ( $localizable_taxonomies as $taxonomy ) {
continue; if ( empty( $taxonomy->rewrite ) ) {
} continue;
}
$permastruct = $wp_rewrite->get_extra_permastruct( $tax ); $permastruct = $wp_rewrite->get_extra_permastruct( $taxonomy->name );
$permastruct = bogo_add_lang_to_permastruct( $permastruct );
if ( $tax_obj->rewrite['with_front'] ) { $extra_rules += bogo_generate_rewrite_rules(
$permastruct = preg_replace( $permastruct,
'#^' . $wp_rewrite->front . '#', $taxonomy->rewrite
'/%lang%' . $wp_rewrite->front, );
$permastruct }
);
} else {
$permastruct = preg_replace(
'#^' . $wp_rewrite->root . '#',
'/%lang%/' . $wp_rewrite->root,
$permastruct
);
}
$rules = array_merge( $root_rules = bogo_generate_rewrite_rules(
bogo_generate_rewrite_rules( $permastruct, $tax_obj->rewrite ), bogo_add_lang_to_permastruct( $wp_rewrite->root ),
$rules array( 'ep_mask' => EP_ROOT )
); );
}
$comments_rules = bogo_generate_rewrite_rules(
bogo_add_lang_to_permastruct(
$wp_rewrite->root . $wp_rewrite->comments_base
),
array(
'ep_mask' => EP_COMMENTS,
'forcomments' => true,
'walk_dirs' => false,
)
);
$search_rules = bogo_generate_rewrite_rules(
bogo_add_lang_to_permastruct( $wp_rewrite->get_search_permastruct() ),
array( 'ep_mask' => EP_SEARCH )
);
$author_rules = bogo_generate_rewrite_rules(
bogo_add_lang_to_permastruct( $wp_rewrite->get_author_permastruct() ),
array( 'ep_mask' => EP_AUTHORS )
);
$date_rules = bogo_generate_rewrite_rules(
bogo_add_lang_to_permastruct( $wp_rewrite->get_date_permastruct() ),
array( 'ep_mask' => EP_DATE )
);
$post_rules = bogo_generate_rewrite_rules(
bogo_add_lang_to_permastruct( $wp_rewrite->permalink_structure ),
array(
'ep_mask' => EP_PERMALINK,
'paged' => false,
)
);
$wp_rewrite->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' );
$page_rules = bogo_generate_rewrite_rules(
bogo_add_lang_to_permastruct( $wp_rewrite->get_page_permastruct() ),
array(
'ep_mask' => EP_PAGES,
'walk_dirs' => false,
)
);
if ( $wp_rewrite->use_verbose_page_rules ) {
$rules = array_merge(
$extra_rules,
$root_rules,
$comments_rules,
$search_rules,
$author_rules,
$date_rules,
$page_rules,
$post_rules,
$rules
);
} else {
$rules = array_merge(
$extra_rules,
$root_rules,
$comments_rules,
$search_rules,
$author_rules,
$date_rules,
$post_rules,
$page_rules,
$rules
);
} }
return $rules; return $rules;
} }
function bogo_add_lang_to_permastruct( $permastruct ) {
global $wp_rewrite;
$root_quoted = preg_quote( $wp_rewrite->root );
$remains = preg_replace( "#^{$root_quoted}#", '', $permastruct );
$remains = path_join( '%lang%', ltrim( $remains, '/' ) );
return path_join( $wp_rewrite->root, $remains );
}
function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) { function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) {
global $wp_rewrite; global $wp_rewrite;
$defaults = array( $args = wp_parse_args( $args, array(
'ep_mask' => EP_NONE, 'ep_mask' => EP_NONE,
'paged' => true, 'paged' => true,
'feed' => true, 'feed' => true,
'forcomments' => false, 'forcomments' => false,
'walk_dirs' => true, 'walk_dirs' => true,
'endpoints' => true, 'endpoints' => true,
); ) );
$args = wp_parse_args( $args, $defaults );
extract( $args, EXTR_SKIP ); if ( strpos( $permalink_structure, '%lang%' ) === false ) {
return array();
}
$feedregex2 = '(' . implode( '|', $wp_rewrite->feeds ) . ')/?$'; $feedregex2 = '(' . implode( '|', $wp_rewrite->feeds ) . ')/?$';
$feedregex = $wp_rewrite->feed_base . '/' . $feedregex2; $feedregex = $wp_rewrite->feed_base . '/' . $feedregex2;
$trackbackregex = 'trackback/?$'; $trackbackregex = 'trackback/?$';
$pageregex = $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$'; $pageregex = $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$';
$commentregex = 'comment-page-([0-9]{1,})/?$'; $commentregex = $wp_rewrite->comments_pagination_base . '-([0-9]{1,})/?$';
$embedregex = 'embed/?$'; $embedregex = 'embed/?$';
if ( $endpoints ) { if ( $args['endpoints'] ) {
$ep_query_append = array(); $ep_query_append = array();
foreach ( (array) $wp_rewrite->endpoints as $endpoint ) { foreach ( (array) $wp_rewrite->endpoints as $endpoint ) {
$epmatch = $endpoint[1] . '(/(.*))?/?$'; $epmatch = $endpoint[1] . '(/(.*))?/?$';
$epquery = '&' . $endpoint[1] . '='; $epquery = '&' . $endpoint[2] . '=';
$ep_query_append[$epmatch] = array( $endpoint[0], $epquery ); $ep_query_append[$epmatch] = array( $endpoint[0], $epquery );
} }
} }
$front = substr( $permalink_structure, 0, strpos( $permalink_structure, '%' ) ); $front = substr(
$permalink_structure,
0,
strpos( $permalink_structure, '%' )
);
preg_match_all( '/%.+?%/', $permalink_structure, $tokens ); preg_match_all( '/%.+?%/', $permalink_structure, $tokens );
$num_tokens = count( $tokens[0] );
$index = $wp_rewrite->index; $index = $wp_rewrite->index;
$feedindex = $index; $feedindex = $index;
$trackbackindex = $index; $trackbackindex = $index;
$embedindex = $index; $embedindex = $index;
for ( $i = 0; $i < $num_tokens; ++$i ) { $queries = array();
for ( $i = 0; $i < count( $tokens[0] ); ++$i ) {
if ( 0 < $i ) { if ( 0 < $i ) {
$queries[$i] = $queries[$i - 1] . '&'; $queries[$i] = $queries[$i - 1] . '&';
} else { } else {
$queries[$i] = ''; $queries[$i] = '';
} }
$query_token = $query_token = str_replace(
str_replace( $wp_rewrite->rewritecode, $wp_rewrite->queryreplace, $tokens[0][$i] ) $wp_rewrite->rewritecode,
. $wp_rewrite->preg_index( $i + 1 ); $wp_rewrite->queryreplace,
$tokens[0][$i]
) . $wp_rewrite->preg_index( $i + 1 );
$queries[$i] .= $query_token; $queries[$i] .= $query_token;
} }
$structure = $permalink_structure; $structure = $permalink_structure;
if ( $front != '/' ) { if ( '/' !== $front ) {
$structure = str_replace( $front, '', $structure ); $structure = str_replace( $front, '', $structure );
} }
$structure = trim( $structure, '/' ); $structure = trim( $structure, '/' );
$dirs = $walk_dirs ? explode( '/', $structure ) : array( $structure ); $dirs = $args['walk_dirs']
$num_dirs = count( $dirs ); ? explode( '/', $structure )
: array( $structure );
$front = preg_replace( '|^/+|', '', $front ); $front = preg_replace( '|^/+|', '', $front );
$post_rewrite = array(); $post_rewrite = array();
$struct = $front; $struct = $front;
for ( $j = 0; $j < $num_dirs; ++$j ) { for ( $j = 0; $j < count( $dirs ); ++$j ) {
$struct .= $dirs[$j] . '/'; $struct .= $dirs[$j] . '/';
$struct = ltrim( $struct, '/' ); $struct = ltrim( $struct, '/' );
$match = str_replace( $wp_rewrite->rewritecode, $wp_rewrite->rewritereplace, $struct);
$match = str_replace(
$wp_rewrite->rewritecode,
$wp_rewrite->rewritereplace,
$struct
);
$num_toks = preg_match_all( '/%.+?%/', $struct, $toks ); $num_toks = preg_match_all( '/%.+?%/', $struct, $toks );
$query = ( isset( $queries ) && is_array( $queries ) && ! empty( $num_toks ) ) if ( $num_toks < count( $tokens[0] )
? $queries[$num_toks - 1] : ''; and $toks[0] === array( '%lang%' ) ) {
continue;
}
$query = ( ! empty( $num_toks ) && isset( $queries[$num_toks - 1] ) )
? $queries[$num_toks - 1]
: '';
switch ( $dirs[$j] ) { switch ( $dirs[$j] ) {
case '%year%': case '%year%':
...@@ -456,34 +331,48 @@ function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) { ...@@ -456,34 +331,48 @@ function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) {
$feedquery2 = $feedindex . '?' . $query $feedquery2 = $feedindex . '?' . $query
. '&feed=' . $wp_rewrite->preg_index( $num_toks + 1 ); . '&feed=' . $wp_rewrite->preg_index( $num_toks + 1 );
if ( $forcomments ) { $embedmatch = $match . $embedregex;
$embedquery = $embedindex . '?' . $query . '&embed=true';
if ( $args['forcomments'] ) {
$feedquery .= '&withcomments=1'; $feedquery .= '&withcomments=1';
$feedquery2 .= '&withcomments=1'; $feedquery2 .= '&withcomments=1';
} }
$rewrite = array(); $rewrite = array();
if ( $feed ) { if ( $args['feed'] ) {
$rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 ); $rewrite = array(
$feedmatch => $feedquery,
$feedmatch2 => $feedquery2,
$embedmatch => $embedquery,
);
} }
if ( $paged ) { if ( $args['paged'] ) {
$rewrite = array_merge( $rewrite, array( $pagematch => $pagequery ) ); $rewrite = array_merge(
$rewrite,
array( $pagematch => $pagequery )
);
} }
if ( EP_PAGES & $ep_mask if ( EP_PAGES & $args['ep_mask']
or EP_PERMALINK & $ep_mask ) { or EP_PERMALINK & $args['ep_mask'] ) {
$rewrite = array_merge( $rewrite, array( $commentmatch => $commentquery ) ); $rewrite = array_merge(
} elseif ( EP_ROOT & $ep_mask $rewrite,
array( $commentmatch => $commentquery )
);
} elseif ( EP_ROOT & $args['ep_mask']
and get_option( 'page_on_front' ) ) { and get_option( 'page_on_front' ) ) {
$rewrite = array_merge( $rewrite, $rewrite = array_merge(
$rewrite,
array( $rootcommentmatch => $rootcommentquery ) array( $rootcommentmatch => $rootcommentquery )
); );
} }
if ( $endpoints ) { if ( $args['endpoints'] ) {
foreach ( (array) $ep_query_append as $regex => $ep ) { foreach ( (array) $ep_query_append as $regex => $ep ) {
if ( $ep[0] & $ep_mask if ( $ep[0] & $args['ep_mask']
or $ep[0] & $ep_mask_specific ) { or $ep[0] & $ep_mask_specific ) {
$rewrite[$match . $regex] = $index . '?' . $query $rewrite[$match . $regex] = $index . '?' . $query
. $ep[1] . $wp_rewrite->preg_index( $num_toks + 2 ); . $ep[1] . $wp_rewrite->preg_index( $num_toks + 2 );
...@@ -551,13 +440,13 @@ function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) { ...@@ -551,13 +440,13 @@ function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) {
$subcommentquery = $subquery . '&cpage=' . $wp_rewrite->preg_index( 2 ); $subcommentquery = $subquery . '&cpage=' . $wp_rewrite->preg_index( 2 );
$subembedquery = $subquery . '&embed=true'; $subembedquery = $subquery . '&embed=true';
if ( ! empty( $endpoints ) ) { if ( ! empty( $args['endpoints'] ) ) {
foreach ( (array) $ep_query_append as $regex => $ep ) { foreach ( (array) $ep_query_append as $regex => $ep ) {
if ( $ep[0] & EP_ATTACHMENT ) { if ( $ep[0] & EP_ATTACHMENT ) {
$rewrite[$sub1 . $regex] = $rewrite[$sub1 . $regex] =
$subquery . $ep[1] . $wp_rewrite->preg_index( 2 ); $subquery . $ep[1] . $wp_rewrite->preg_index( 3 );
$rewrite[$sub2 . $regex] = $rewrite[$sub2 . $regex] =
$subquery . $ep[1] . $wp_rewrite->preg_index( 2 ); $subquery . $ep[1] . $wp_rewrite->preg_index( 3 );
} }
} }
} }
...@@ -565,7 +454,7 @@ function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) { ...@@ -565,7 +454,7 @@ function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) {
$sub1 .= '?$'; $sub1 .= '?$';
$sub2 .= '?$'; $sub2 .= '?$';
$match = $match . '(/[0-9]+)?/?$'; $match = $match . '(?:/([0-9]+))?/?$';
$query = $index . '?' . $query $query = $index . '?' . $query
. '&page=' . $wp_rewrite->preg_index( $num_toks + 1 ); . '&page=' . $wp_rewrite->preg_index( $num_toks + 1 );
} else { } else {
...@@ -576,27 +465,41 @@ function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) { ...@@ -576,27 +465,41 @@ function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) {
$rewrite = array_merge( $rewrite, array( $match => $query ) ); $rewrite = array_merge( $rewrite, array( $match => $query ) );
if ( $post ) { if ( $post ) {
$rewrite = array_merge( array( $trackbackmatch => $trackbackquery ), $rewrite ); $rewrite = array_merge(
array( $trackbackmatch => $trackbackquery ),
$rewrite
);
$rewrite = array_merge( array( $embedmatch => $embedquery ), $rewrite ); $rewrite = array_merge(
array( $embedmatch => $embedquery ),
$rewrite
);
if ( ! $page ) { if ( ! $page ) {
$rewrite = array_merge( $rewrite, array( $rewrite = array_merge(
$sub1 => $subquery, $rewrite,
$sub1tb => $subtbquery, array(
$sub1feed => $subfeedquery, $sub1 => $subquery,
$sub1feed2 => $subfeedquery, $sub1tb => $subtbquery,
$sub1comment => $subcommentquery, $sub1feed => $subfeedquery,
$sub1embed => $subembedquery ) ); $sub1feed2 => $subfeedquery,
$sub1comment => $subcommentquery,
$sub1embed => $subembedquery,
)
);
} }
$rewrite = array_merge( array( $rewrite = array_merge(
$sub2 => $subquery, array(
$sub2tb => $subtbquery, $sub2 => $subquery,
$sub2feed => $subfeedquery, $sub2tb => $subtbquery,
$sub2feed2 => $subfeedquery, $sub2feed => $subfeedquery,
$sub2comment => $subcommentquery, $sub2feed2 => $subfeedquery,
$sub2embed => $subembedquery ), $rewrite ); $sub2comment => $subcommentquery,
$sub2embed => $subembedquery,
),
$rewrite
);
} }
} }
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
/* Toolbar (Admin Bar) */ /* Toolbar (Admin Bar) */
add_action( 'admin_bar_init', 'bogo_admin_bar_init', 10, 0 ); add_action( 'admin_bar_menu', 'bogo_admin_bar_init', 0, 1 );
function bogo_admin_bar_init() { function bogo_admin_bar_init( $wp_admin_bar ) {
switch_to_locale( bogo_get_user_locale() ); switch_to_locale( bogo_get_user_locale() );
} }
......
This diff is collapsed.
=== Bogo === === Bogo ===
Contributors: takayukister, itpixelz Contributors: takayukister, itpixelz
Tags: multilingual, localization, language, locale, admin Tags: multilingual, localization, language, locale, admin
Requires at least: 5.3 Requires at least: 5.5
Tested up to: 5.4 Tested up to: 5.7
Stable tag: 3.3.2 Stable tag: 3.5
License: GPLv2 or later License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html License URI: https://www.gnu.org/licenses/gpl-2.0.html
Donate link: https://contactform7.com/donate/ Donate link: https://contactform7.com/donate/
A straight-forward multilingual plugin. No more double-digit custom DB tables or hidden HTML comments that could cause you headaches later on. A straight-forward multilingual plugin. No more double-digit custom DB tables or hidden HTML comments that could cause you headaches later on.
== Description == == Description ==
https://ideasilo.wordpress.com/bogo/ https://ideasilo.wordpress.com/bogo/
Bogo is a straight-forward multilingual plugin for WordPress. Bogo is a straight-forward multilingual plugin for WordPress.
The core of WordPress itself has the built-in localization capability so you can use the dashboard and theme in one language other than English. Bogo expands this capability to let you easily build a multilingual blog on a single WordPress install. The core of WordPress itself has the built-in localization capability so you can use the dashboard and theme in one language other than English. Bogo expands this capability to let you easily build a multilingual blog on a single WordPress install.
Here are some technical details for those interested. Bogo plugin assigns [one language per post](https://wordpress.org/support/article/multilingual-wordpress/#different-types-of-multilingual-plugins). It plays nice with WordPress – Bogo does not create any additional custom table on your database, unlike some other plugins in this category. This design makes Bogo a solid, reliable and conflict-free multilingual plugin. Here are some technical details for those interested. Bogo plugin assigns [one language per post](https://wordpress.org/support/article/multilingual-wordpress/#different-types-of-multilingual-plugins). It plays nice with WordPress – Bogo does not create any additional custom table on your database, unlike some other plugins in this category. This design makes Bogo a solid, reliable and conflict-free multilingual plugin.
= Getting started with Bogo = = Getting started with Bogo =
1. Install language packs 1. Install language packs
First, install language packs for languages you use on the site. You can view and install language packs in the **Language Packs** screen (**Languages > Language Packs**). First, install language packs for languages you use on the site. You can view and install language packs in the **Language Packs** screen (**Languages > Language Packs**).
2. Select your language for admin screen 2. Select your language for admin screen
Bogo lets each logged-in user select a language for their admin screen UI. Select a language from the menu on the [**Toolbar**](https://wordpress.org/support/article/administration-screens/#toolbar-keeping-it-all-together), or from the menu in the **Profile** screen (**Users > Your Profile**) if the **Toolbar** is invisible. Bogo lets each logged-in user select a language for their admin screen UI. Select a language from the menu on the [**Toolbar**](https://wordpress.org/support/article/administration-screens/#toolbar-keeping-it-all-together), or from the menu in the **Profile** screen (**Users > Your Profile**) if the **Toolbar** is invisible.
3. Translate your posts and pages 3. Translate your posts and pages
To create a translation post, go to the editor screen for the original post and find the **Language** box. Bogo does only make a copy of the post; translating the copied post is your task. To create a translation post, go to the editor screen for the original post and find the **Language** box. Bogo does only make a copy of the post; translating the copied post is your task.
4. Add language switcher widgets 4. Add language switcher widgets
It would be useful for site visitors if you have a language switcher on your site. Bogo provides the **Language Switcher** widget in the **Widgets** screen (**Appearance > Widgets**). It would be useful for site visitors if you have a language switcher on your site. Bogo provides the **Language Switcher** widget in the **Widgets** screen (**Appearance > Widgets**).
You can also use the `[bogo]` shortcode to put a language switcher inside a post content. If you want to use this shortcode in your theme's template files, embed the following code into the template: You can also use the `[bogo]` shortcode to put a language switcher inside a post content. If you want to use this shortcode in your theme's template files, embed the following code into the template:
`<?php echo do_shortcode( '[bogo]' ); ?>` `<?php echo do_shortcode( '[bogo]' ); ?>`
= Privacy notices = = Privacy notices =
With the default configuration, this plugin, in itself, does not: With the default configuration, this plugin, in itself, does not:
* track users by stealth; * track users by stealth;
* write any user personal data to the database; * write any user personal data to the database;
* send any data to external servers; * send any data to external servers;
* use cookies. * use cookies.
== Installation == == Installation ==
1. Upload the entire `bogo` folder to the `/wp-content/plugins/` directory. 1. Upload the entire `bogo` folder to the `/wp-content/plugins/` directory.
1. Activate the plugin through the **Plugins** screen (**Plugins > Installed Plugins**). 1. Activate the plugin through the **Plugins** screen (**Plugins > Installed Plugins**).
== Screenshots == == Screenshots ==
1. You can select your language in the **Toolbar**. 1. You can select your language in the **Toolbar**.
1. The **Language** box manages the post's translations. 1. The **Language** box manages the post's translations.
1. The **Language Packs** screen lets you view and install language packs. 1. The **Language Packs** screen lets you view and install language packs.
== Changelog == == Changelog ==
= 3.3.2 = = 3.5 =
* User locale: Fixes several issues seen when you are logged-in as a non-Administrator role user. * Adds `auth_callback` to post meta definition.
* User locale: Renders the **Toolbar** in the logged-in user's locale even on the front side. * Suppresses locale query for XML sitemap.
* Capabilities: Editor role users can now access the **Terms Translation** page, but higher level capabilities are required to edit some of translation items. * Corrects several rewrite rules-related issues.
* Makes the `exclude_enus_if_inactive` option true by default.
* New filter hook: `bogo_get_short_name` = 3.4 =
= 3.3.1 = * Modernize the JS build process.
* Uses `__()` in JavaScript.
* Block Editor: Displays a spinner icon when creating a translation post. * Has removed some unused functions and variables.
* Block Editor: Suggests posts in the same locale as the current post when making a text link or doing other operations in a block. * Has been tested with WordPress 5.6.
* Block Editor: Fixes the issue that character references appear in post titles.
= 3.3 =
* Supports Block Editor.
* Adds the `short_name` option to `bogo_available_languages()`.
* Uses the post guid for the value of the `_original_post` post meta.
* Improves HTML markup of the language switcher.
= 3.2.1 =
* Recalculates values in some WP query parameters in bogo_parse_query().
= 3.2 =
* Uses the install_languages as the default capability required for the Language Packs page.
* Adds rel="noopener noreferrer" and screenreader text to target="_blank" links.
* Adds a filter hook: bogo_terms_translation.
* Introduces the Bogo_Terms_Translation_List_Table class.
* Introduces the Bogo_Language_Packs_List_Table class.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment