Skip to content

Commit

Permalink
1.4.1 - Fixed non existing function (early) call for some 3rd party p…
Browse files Browse the repository at this point in the history
…lugins.
  • Loading branch information
richardevcom committed May 22, 2021
0 parents commit 637ce7b
Show file tree
Hide file tree
Showing 28 changed files with 1,600 additions and 0 deletions.
Empty file added .gitignore
Empty file.
339 changes: 339 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions apsfc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* Add Polylang support for Customizer
*
* @link https://richardev.com
* @since 1.4.1
* @package Polylang_Customizer
*
* @wordpress-plugin
* Plugin Name: Add Polylang support for Customizer
* Plugin URI: https://wordpress.org/plugins/add-polylang-support-for-customizer
* Description: This plugin adds Polylang support for Customizer.
* Version: 1.4.1
* Author: richardev
* Author URI: https://richardev.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: apsfc
* Domain Path: /languages
*/

// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}

if (!defined('POLYLANG_VERSION')) {
function apsfc_error_notice__error()
{
$class = 'notice notice-error';
$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');

printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), $message);
}
add_action('admin_notices', 'apsfc_error_notice__error');
} else {
/**
* Currently plugin version.
* Start at version 1.0.2 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define('APSFC_VERSION', '1.4.1');
define('APSFC_BASENAME', plugin_basename(__FILE__));

require_once plugin_dir_path(__FILE__) . '/includes/class-apsfc.php';
}
1 change: 1 addition & 0 deletions assets/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
68 changes: 68 additions & 0 deletions assets/js/apsfc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
*
*/
/* global wp, jQuery */
/* exported PluginCustomizer */
var PSPolyLang = (function( api, $ ) {
'use strict';

var component = {
data: {
url: null,
languages: null,
current_language: null,
}
};

/**
* Initialize functionality.
*
* @param {object} args Args.
* @param {string} args.url Preview URL.
* @returns {void}
*/
component.init = function init( pll ) {
_.extend(component.data, pll );
if (!pll || !pll.url || !pll.languages || !pll.current_language ) {
throw new Error( 'Missing args' );
}

api.bind( 'ready', function(){
api.previewer.previewUrl.set( pll.url );

var languages = pll.languages;
var current_language = pll.current_language;
var current_language_name = '';

var html = '<span style="position:relative;left:38px;margin-right:5px;top:2.5px;margin-left:5px;">' + pcLangTrans + ': </span>';
html += '<select id="pll-language-select" style="position:relative; left: 35px; top: 1px; padding: 4px 1px;width: 50px;">';
for (var i = 0; i < languages.length; i++) {
var language = languages[i];
var selected = (language.slug === current_language) ? 'selected=""' : '';
current_language_name = (language.slug === current_language) ? language.name.substr(0, 3) : 'Eng';
html += '<option ' + selected + ' value="' + language.slug + '">' + language.name.substr(0, 3) + '</option>';
}
html += '</select>';
$(html).prependTo('#customize-header-actions');


$('body').on('change', '#pll-language-select', function () {
var language = $(this).val();
var old_url = window.location.href;
window.location.href = updateQueryStringParameter(window.location.href, 'lang', language);
});
});

function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
} else {
return uri + separator + key + "=" + value;
}
}
};

return component;
} ( wp.customize, jQuery ) );
1 change: 1 addition & 0 deletions assets/js/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
Loading

0 comments on commit 637ce7b

Please sign in to comment.