Skip to content

Commit

Permalink
Initial working commit
Browse files Browse the repository at this point in the history
  • Loading branch information
skaparate committed Feb 27, 2018
1 parent 744ec24 commit ede8721
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# cf7-pll-recaptcha
A simple Wordpress plugin that changes the Contact Forms 7 recaptcha language to the current language of Polylang.
# Contact Form 7 Polylang Recaptcha

A simple Wordpress plugin that changes the Contact Form 7 recaptcha language to the current language of Polylang (the one chosen by the user).

## Requirements

This plugin requires [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) and [Polylang](https://wordpress.org/plugins/polylang/) to be installed and active.
29 changes: 29 additions & 0 deletions i18n/I18n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Nicomv\Cf7\Polylang\Recaptcha\I18n;

/**
* Define the internationalization functionality.
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @since 0.0.1
* @package Nicomv\Cf7\Polylang\Recaptcha
* @subpackage Nicomv\Cf7\Polylang\Recaptcha\I18n
* @author Your Name <[email protected]>
*/
class I18n {
/**
* Load the plugin text domain for translation.
*
* @since 0.0.1
*/
public function loadTextDomain() {
load_plugin_textdomain(
'nmv-cf7-pll-recaptcha',
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);
}
}
1 change: 1 addition & 0 deletions i18n/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
60 changes: 60 additions & 0 deletions includes/Core.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Nicomv\Cf7\Polylang\Recaptcha\Includes;

/**
* The main functionalaty of this plugin.
*/
class Core
{
/**
* Retrieves the recaptcha api for the current polylang language.
* @param string $src The script src.
* @param string $handle The script handle, as defined in wp_register_script.
* @return string A modified version of the api uri or the unmodified one
* if the $handle doesn't match with the one defined by contact forms 7.
*/
public function getScriptSrc($src, $handle)
{
if ($handle !== 'google-recaptcha') {
return $src;
}
return 'https://google.com/recaptcha/api.js?hl=' . strtolower(pll_current_language());
}

public function run()
{
$this->loadLang();
if (is_admin()) {
add_action('admin_init', array($this, 'checkRequiredPlugins'));
} else {
$this->addFilters();
}
}

private function loadLang()
{
require_once NMV_CF7_PLL_RECAPTCHA_PATH . 'i18n/I18n.php';
$i18n = new \Nicomv\Cf7\Polylang\Recaptcha\I18n\I18n;
add_action('plugins_loaded', array($i18n, 'loadTextDomain'));
}

public function noPluginsNotice()
{
include_once NMV_CF7_PLL_RECAPTCHA_PATH . 'includes/no-plugins.php';
}

public function checkRequiredPlugins()
{
if (!is_plugin_active('contact-form-7/wp-contact-form-7.php') || !is_plugin_active('polylang/polylang.php')) {
add_action('admin_notices', array($this, 'noPluginsNotice'));
return false;
}
return true;
}

public function addFilters()
{
add_filter('script_loader_src', array($this, 'getScriptSrc'), 10, 2);
}
}
1 change: 1 addition & 0 deletions includes/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
7 changes: 7 additions & 0 deletions includes/no-plugins.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="notice notice-error is-dismissible">
<p><?php _e('Los plugins necesarios no están habilitados. ', 'nmv-cf7-pll-recaptcha'); ?>
<?=sprintf(
__('Revise el siguiente enlace para saber qué plugins necesita: %s', 'nmv-cf7-pll-recaptcha'),
'https://github.com/skaparate/cf7-pll-recaptcha' ); ?>
</p>
</div>
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
1 change: 1 addition & 0 deletions languages/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
Binary file added languages/nmv-cf7-pll-recaptcha-en_GB.mo
Binary file not shown.
26 changes: 26 additions & 0 deletions languages/nmv-cf7-pll-recaptcha-en_GB.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2018-02-27 00:56-0300\n"
"PO-Revision-Date: 2018-02-27 00:57-0300\n"
"Last-Translator: \n"
"Language-Team: [email protected] <[email protected]>\n"
"Language: en_GB\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.11\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e\n"
"X-Poedit-SearchPath-0: .\n"

#: includes/no-plugins.php:2
msgid "Los plugins necesarios no están habilitados. "
msgstr "The required plugins are disabled."

#: includes/no-plugins.php:4
#, php-format
msgid "Revise el siguiente enlace para saber qué plugins necesita: %s"
msgstr "Check the following link to know which plugins are needed: %s"
Binary file added languages/nmv-cf7-pll-recaptcha.mo
Binary file not shown.
26 changes: 26 additions & 0 deletions languages/nmv-cf7-pll-recaptcha.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2018-02-27 00:56-0300\n"
"PO-Revision-Date: 2018-02-27 00:57-0300\n"
"Last-Translator: \n"
"Language-Team: [email protected] <[email protected]>\n"
"Language: en_GB\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.11\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e\n"
"X-Poedit-SearchPath-0: .\n"

#: includes/no-plugins.php:2
msgid "Los plugins necesarios no están habilitados. "
msgstr "The required plugins are disabled."

#: includes/no-plugins.php:4
#, php-format
msgid "Revise el siguiente enlace para saber qué plugins necesita: %s"
msgstr "Check the following link to know which plugins are needed: %s"
43 changes: 43 additions & 0 deletions nmv-cf7-pll-recaptcha.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Nicomv\Cf7\Polylang\Recaptcha;

/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link http://nicomv.com
* @since 0.0.2
* @package Nicomv\Cf7\Polylang\Recaptcha
*
* @wordpress-plugin
* Plugin Name: Contact Form 7 Polylang Recaptcha
* Plugin URI: https://github.com/skaparate/cf7-pll-recaptcha/
* Description: A simple plugin that changes the recaptcha API URI language.
* Version: 0.0.2
* Author: nicomv.com
* Author URI: http://nicomv.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: nmv-cf7-pll-recaptcha
* Domain Path: /languages
*/

if (! defined('WPINC')) {
die;
}

define('NMV_CF7_PLL_RECAPTCHA_PATH', plugin_dir_path(__FILE__));

function run()
{
require_once NMV_CF7_PLL_RECAPTCHA_PATH.'includes/Core.php';
$core = new \Nicomv\Cf7\Polylang\Recaptcha\Includes\Core;
$core->run();
return true;
}
run();

0 comments on commit ede8721

Please sign in to comment.