Skip to content

Commit 2c2e2f4

Browse files
committed
Added Polylang pro directory support
0 parents  commit 2c2e2f4

26 files changed

+1469
-0
lines changed

LICENSE.txt

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

apsfc.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* Add Polylang support for Customizer
5+
*
6+
* @link https://richardev.com
7+
* @since 1.3.4
8+
* @package Polylang_Customizer
9+
*
10+
* @wordpress-plugin
11+
* Plugin Name: Add Polylang support for Customizer
12+
* Plugin URI: https://wordpress.org/plugins/add-polylang-support-for-customizer
13+
* Description: This plugin adds Polylang support for Customizer.
14+
* Version: 1.3.4
15+
* Author: richardev
16+
* Author URI: https://richardev.com
17+
* License: GPL-2.0+
18+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
19+
* Text Domain: apsfc
20+
* Domain Path: /languages
21+
*/
22+
23+
// If this file is called directly, abort.
24+
if ( ! defined( 'WPINC' ) ) {
25+
die;
26+
}
27+
28+
if( ! defined( 'POLYLANG_VERSION' )){
29+
function apsfc_error_notice__error() {
30+
$class = 'notice notice-error';
31+
$message = __( '<strong>Polylang</strong> plugin must be activated for <strong>Add Polylang support for Customizer</strong> plugin to work. Please <a href="' . admin_url('plugins.php') .'">activate it</a> now!', 'sample-text-domain' );
32+
33+
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message );
34+
}
35+
add_action( 'admin_notices', 'apsfc_error_notice__error' );
36+
}else{
37+
/**
38+
* Currently plugin version.
39+
* Start at version 1.0.2 and use SemVer - https://semver.org
40+
* Rename this for your plugin and update it as you release new versions.
41+
*/
42+
define( 'APSFC_VERSION', '1.3.4' );
43+
define( 'APSFC_BASENAME', plugin_basename(__FILE__));
44+
45+
require_once plugin_dir_path( __FILE__ ) . '/includes/class-apsfc.php';
46+
}

assets/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php // Silence is golden

assets/js/apsfc.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
*
3+
*/
4+
/* global wp, jQuery */
5+
/* exported PluginCustomizer */
6+
var PSPolyLang = (function( api, $ ) {
7+
'use strict';
8+
9+
var component = {
10+
data: {
11+
url: null,
12+
languages: null,
13+
current_language: null,
14+
}
15+
};
16+
17+
/**
18+
* Initialize functionality.
19+
*
20+
* @param {object} args Args.
21+
* @param {string} args.url Preview URL.
22+
* @returns {void}
23+
*/
24+
component.init = function init( pll ) {
25+
_.extend(component.data, pll );
26+
if (!pll || !pll.url || !pll.languages || !pll.current_language ) {
27+
throw new Error( 'Missing args' );
28+
}
29+
30+
api.bind( 'ready', function(){
31+
api.previewer.previewUrl.set( pll.url );
32+
33+
var languages = pll.languages;
34+
var current_language = pll.current_language;
35+
var current_language_name = '';
36+
37+
var html = '<span style="position:relative;left:38px;margin-right:5px;top:2.5px;margin-left:5px;">' + pcLangTrans + ': </span>';
38+
html += '<select id="pll-language-select" style="position:relative; left: 35px; top: 1px; padding: 4px 1px;width: 50px;">';
39+
for (var i = 0; i < languages.length; i++) {
40+
var language = languages[i];
41+
var selected = (language.slug === current_language) ? 'selected=""' : '';
42+
current_language_name = (language.slug === current_language) ? language.name.substr(0, 3) : 'Eng';
43+
html += '<option ' + selected + ' value="' + language.slug + '">' + language.name.substr(0, 3) + '</option>';
44+
}
45+
html += '</select>';
46+
$(html).prependTo('#customize-header-actions');
47+
48+
49+
$('body').on('change', '#pll-language-select', function () {
50+
var language = $(this).val();
51+
var old_url = window.location.href;
52+
window.location.href = updateQueryStringParameter(window.location.href, 'lang', language);
53+
});
54+
});
55+
56+
function updateQueryStringParameter(uri, key, value) {
57+
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
58+
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
59+
if (uri.match(re)) {
60+
return uri.replace(re, '$1' + key + "=" + value + '$2');
61+
} else {
62+
return uri + separator + key + "=" + value;
63+
}
64+
}
65+
};
66+
67+
return component;
68+
} ( wp.customize, jQuery ) );

assets/js/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php // Silence is golden

0 commit comments

Comments
 (0)