Version Description
2019-08-25 = + Added WPML compatibility.
Download this release
Release Info
Developer | theluckywp |
Plugin | LuckyWP Table of Contents |
Version | 1.9.3 |
Comparing to | |
See all releases |
Code changes from version 1.9.2 to 1.9.3
- integrations/Wpml.php +107 -0
- luckywp-table-of-contents.php +2 -2
- plugin/Plugin.php +4 -0
- plugin/WpWidget.php +5 -1
- readme.txt +16 -1
- wpml-config.xml +26 -0
integrations/Wpml.php
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace luckywp\tableOfContents\integrations;
|
4 |
+
|
5 |
+
use luckywp\tableOfContents\core\base\BaseObject;
|
6 |
+
use luckywp\tableOfContents\core\helpers\ArrayHelper;
|
7 |
+
use luckywp\tableOfContents\plugin\Shortcode;
|
8 |
+
use luckywp\tableOfContents\plugin\WpWidget;
|
9 |
+
|
10 |
+
class Wpml extends BaseObject
|
11 |
+
{
|
12 |
+
|
13 |
+
const CONTEXT = 'LuckyWP Table of Contents';
|
14 |
+
|
15 |
+
public function init()
|
16 |
+
{
|
17 |
+
add_filter('lwptoc_widget_attrs', [$this, 'widgetAttrs'], 10, 2);
|
18 |
+
add_action('lwptoc_widget_attrs_update', [$this, 'widgetAttrsUpdate'], 10, 3);
|
19 |
+
add_action('delete_widget', [$this, 'widgetDelete'], 10, 3);
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @param array $attrs
|
24 |
+
* @param WpWidget $widget
|
25 |
+
* @return array
|
26 |
+
*/
|
27 |
+
public function widgetAttrs($attrs, $widget)
|
28 |
+
{
|
29 |
+
foreach ($this->getAttrs() as $key => $label) {
|
30 |
+
if (isset($attrs[$key])) {
|
31 |
+
$attrs[$key] = apply_filters(
|
32 |
+
'wpml_translate_single_string',
|
33 |
+
$attrs[$key],
|
34 |
+
Wpml::CONTEXT,
|
35 |
+
$this->getWidgetName($widget->number, $label)
|
36 |
+
);
|
37 |
+
}
|
38 |
+
}
|
39 |
+
return $attrs;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @param array $newInstance
|
44 |
+
* @param array $oldInstance
|
45 |
+
* @param WpWidget $widget
|
46 |
+
*/
|
47 |
+
public function widgetAttrsUpdate($newInstance, $oldInstance, $widget)
|
48 |
+
{
|
49 |
+
$newAttrs = Shortcode::attrsFromJson(ArrayHelper::getValue($newInstance, 'config', ''));
|
50 |
+
$oldAttrs = Shortcode::attrsFromJson(ArrayHelper::getValue($oldInstance, 'config', ''));
|
51 |
+
|
52 |
+
// Удалить старые значения из переводов
|
53 |
+
if (function_exists('icl_unregister_string')) {
|
54 |
+
foreach ($this->getAttrs() as $key => $label) {
|
55 |
+
if (array_key_exists($key, $oldAttrs) && !isset($newAttrs[$key])) {
|
56 |
+
icl_unregister_string(Wpml::CONTEXT, $this->getWidgetName($widget->number, $label));
|
57 |
+
}
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
// Добавить новые значения
|
62 |
+
foreach ($this->getAttrs() as $key => $label) {
|
63 |
+
if (isset($newAttrs[$key])) {
|
64 |
+
do_action('wpml_register_single_string', Wpml::CONTEXT, $this->getWidgetName($widget->number, $label), $newAttrs[$key]);
|
65 |
+
}
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* @param string $widgetId
|
71 |
+
* @param string $sidebarId
|
72 |
+
* @param string $idBase
|
73 |
+
*/
|
74 |
+
public function widgetDelete($widgetId, $sidebarId, $idBase)
|
75 |
+
{
|
76 |
+
if (function_exists('icl_unregister_string')) {
|
77 |
+
if ($idBase == WpWidget::ID_BASE) {
|
78 |
+
$number = str_replace($idBase . '-', '', $widgetId);
|
79 |
+
foreach ($this->getAttrs() as $label) {
|
80 |
+
icl_unregister_string(Wpml::CONTEXT, $this->getWidgetName($number, $label));
|
81 |
+
}
|
82 |
+
}
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* @param string $number
|
88 |
+
* @param string $caption
|
89 |
+
* @return string
|
90 |
+
*/
|
91 |
+
protected function getWidgetName($number, $caption)
|
92 |
+
{
|
93 |
+
return 'Widget #' . $number . ': ' . $caption;
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* @return array
|
98 |
+
*/
|
99 |
+
protected function getAttrs()
|
100 |
+
{
|
101 |
+
return [
|
102 |
+
'title' => 'Title',
|
103 |
+
'labelShow' => 'Label Show',
|
104 |
+
'labelHide' => 'Label Hide'
|
105 |
+
];
|
106 |
+
}
|
107 |
+
}
|
luckywp-table-of-contents.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: LuckyWP Table of Contents
|
4 |
Plugin URI: https://theluckywp.com/product/table-of-contents/
|
5 |
Description: Creates a table of contents for your posts/pages. Works automatically or manually (via shortcode, Gutenberg block or widget).
|
6 |
-
Version: 1.9.
|
7 |
Author: LuckyWP
|
8 |
Author URI: https://theluckywp.com/
|
9 |
Text Domain: luckywp-table-of-contents
|
@@ -29,6 +29,6 @@ $lwptocAutoloader->register();
|
|
29 |
$lwptocAutoloader->addNamespace('luckywp\tableOfContents', __DIR__);
|
30 |
|
31 |
$config = require(__DIR__ . '/config/plugin.php');
|
32 |
-
(new \luckywp\tableOfContents\plugin\Plugin($config))->run('1.9.
|
33 |
|
34 |
require_once __DIR__ . '/functions.php';
|
3 |
Plugin Name: LuckyWP Table of Contents
|
4 |
Plugin URI: https://theluckywp.com/product/table-of-contents/
|
5 |
Description: Creates a table of contents for your posts/pages. Works automatically or manually (via shortcode, Gutenberg block or widget).
|
6 |
+
Version: 1.9.3
|
7 |
Author: LuckyWP
|
8 |
Author URI: https://theluckywp.com/
|
9 |
Text Domain: luckywp-table-of-contents
|
29 |
$lwptocAutoloader->addNamespace('luckywp\tableOfContents', __DIR__);
|
30 |
|
31 |
$config = require(__DIR__ . '/config/plugin.php');
|
32 |
+
(new \luckywp\tableOfContents\plugin\Plugin($config))->run('1.9.3', __FILE__, 'lwptoc_');
|
33 |
|
34 |
require_once __DIR__ . '/functions.php';
|
plugin/Plugin.php
CHANGED
@@ -15,6 +15,7 @@ use luckywp\tableOfContents\integrations\BeaverBuilder;
|
|
15 |
use luckywp\tableOfContents\integrations\elementor\Elementor;
|
16 |
use luckywp\tableOfContents\integrations\RankMath;
|
17 |
use luckywp\tableOfContents\integrations\ToolsetViews;
|
|
|
18 |
use luckywp\tableOfContents\plugin\editorBlock\EditorBlock;
|
19 |
use luckywp\tableOfContents\plugin\mcePlugin\McePlugin;
|
20 |
use WP_Post_Type;
|
@@ -74,6 +75,9 @@ class Plugin extends BasePlugin
|
|
74 |
if (defined('ELEMENTOR_VERSION')) {
|
75 |
Core::createObject(Elementor::className());
|
76 |
}
|
|
|
|
|
|
|
77 |
});
|
78 |
}
|
79 |
|
15 |
use luckywp\tableOfContents\integrations\elementor\Elementor;
|
16 |
use luckywp\tableOfContents\integrations\RankMath;
|
17 |
use luckywp\tableOfContents\integrations\ToolsetViews;
|
18 |
+
use luckywp\tableOfContents\integrations\Wpml;
|
19 |
use luckywp\tableOfContents\plugin\editorBlock\EditorBlock;
|
20 |
use luckywp\tableOfContents\plugin\mcePlugin\McePlugin;
|
21 |
use WP_Post_Type;
|
75 |
if (defined('ELEMENTOR_VERSION')) {
|
76 |
Core::createObject(Elementor::className());
|
77 |
}
|
78 |
+
if (class_exists('\SitePress')) {
|
79 |
+
Core::createObject(Wpml::className());
|
80 |
+
}
|
81 |
});
|
82 |
}
|
83 |
|
plugin/WpWidget.php
CHANGED
@@ -10,13 +10,15 @@ use WP_Widget;
|
|
10 |
class WpWidget extends WP_Widget
|
11 |
{
|
12 |
|
|
|
|
|
13 |
/**
|
14 |
* Конструктор
|
15 |
*/
|
16 |
public function __construct()
|
17 |
{
|
18 |
parent::__construct(
|
19 |
-
|
20 |
esc_html__('Table of Contents', 'luckywp-table-of-contents')
|
21 |
);
|
22 |
}
|
@@ -28,6 +30,7 @@ class WpWidget extends WP_Widget
|
|
28 |
public function widget($args, $instance)
|
29 |
{
|
30 |
$attrs = Shortcode::attrsFromJson(ArrayHelper::getValue($instance, 'config', ''));
|
|
|
31 |
echo do_shortcode(Core::$plugin->shortcode->make($attrs));
|
32 |
}
|
33 |
|
@@ -51,6 +54,7 @@ class WpWidget extends WP_Widget
|
|
51 |
*/
|
52 |
public function update($newInstance, $oldInstance)
|
53 |
{
|
|
|
54 |
return ['config' => ArrayHelper::getValue($newInstance, 'config', '')];
|
55 |
}
|
56 |
}
|
10 |
class WpWidget extends WP_Widget
|
11 |
{
|
12 |
|
13 |
+
const ID_BASE = 'lpwtoc_widget';
|
14 |
+
|
15 |
/**
|
16 |
* Конструктор
|
17 |
*/
|
18 |
public function __construct()
|
19 |
{
|
20 |
parent::__construct(
|
21 |
+
self::ID_BASE,
|
22 |
esc_html__('Table of Contents', 'luckywp-table-of-contents')
|
23 |
);
|
24 |
}
|
30 |
public function widget($args, $instance)
|
31 |
{
|
32 |
$attrs = Shortcode::attrsFromJson(ArrayHelper::getValue($instance, 'config', ''));
|
33 |
+
$attrs = apply_filters('lwptoc_widget_attrs', $attrs, $this);
|
34 |
echo do_shortcode(Core::$plugin->shortcode->make($attrs));
|
35 |
}
|
36 |
|
54 |
*/
|
55 |
public function update($newInstance, $oldInstance)
|
56 |
{
|
57 |
+
do_action('lwptoc_widget_attrs_update', $newInstance, $oldInstance, $this);
|
58 |
return ['config' => ArrayHelper::getValue($newInstance, 'config', '')];
|
59 |
}
|
60 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://theluckywp.com/product/table-of-contents/
|
|
4 |
Tags: table of contents, toc, navigation, links, seo
|
5 |
Requires at least: 4.7
|
6 |
Tested up to: 5.2.2
|
7 |
-
Stable tag: 1.9.
|
8 |
Requires PHP: 5.6.20
|
9 |
License: GPLv2 or later
|
10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
@@ -59,6 +59,18 @@ By default, hash generated as heading text (for example, `#How_Do_This`). You ca
|
|
59 |
|
60 |
For non-English websites it is recommended to enable the `Intl` PHP extension.
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
### Hooks
|
63 |
|
64 |
#### Filters `lwptoc_before`, `lwptoc_after`
|
@@ -139,6 +151,9 @@ For non-English websites it is recommended to enable the `Intl` PHP extension.
|
|
139 |
|
140 |
== Changelog ==
|
141 |
|
|
|
|
|
|
|
142 |
= 1.9.2 — 2019-08-11 =
|
143 |
+ Added support Elementor plugin.
|
144 |
|
4 |
Tags: table of contents, toc, navigation, links, seo
|
5 |
Requires at least: 4.7
|
6 |
Tested up to: 5.2.2
|
7 |
+
Stable tag: 1.9.3
|
8 |
Requires PHP: 5.6.20
|
9 |
License: GPLv2 or later
|
10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
59 |
|
60 |
For non-English websites it is recommended to enable the `Intl` PHP extension.
|
61 |
|
62 |
+
### Compatibility
|
63 |
+
|
64 |
+
LuckyWP Table of Contents was successfully tested with the following plugins:
|
65 |
+
|
66 |
+
* Elementor Page Builder
|
67 |
+
* Beaver Builder and Beaver Builder Themer Add-On
|
68 |
+
* WPBakery Page Builder
|
69 |
+
* WordPress Multilingual Plugin (WPML)
|
70 |
+
* Rank Math, [officially confirmed](https://rankmath.com/compatibility/luckywp-table-of-contents/)
|
71 |
+
* WP Rocket
|
72 |
+
* Toolset Views and Toolset Access
|
73 |
+
|
74 |
### Hooks
|
75 |
|
76 |
#### Filters `lwptoc_before`, `lwptoc_after`
|
151 |
|
152 |
== Changelog ==
|
153 |
|
154 |
+
= 1.9.3 — 2019-08-25 =
|
155 |
+
+ Added WPML compatibility.
|
156 |
+
|
157 |
= 1.9.2 — 2019-08-11 =
|
158 |
+ Added support Elementor plugin.
|
159 |
|
wpml-config.xml
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<wpml-config>
|
2 |
+
<shortcodes>
|
3 |
+
<shortcode>
|
4 |
+
<tag>lwptoc</tag>
|
5 |
+
<attributes>
|
6 |
+
<attribute style="line">title</attribute>
|
7 |
+
<attribute style="line">labelshow</attribute>
|
8 |
+
<attribute style="line">labelhide</attribute>
|
9 |
+
</attributes>
|
10 |
+
</shortcode>
|
11 |
+
</shortcodes>
|
12 |
+
<gutenberg-blocks>
|
13 |
+
<gutenberg-block type="luckywp/tableofcontents" translate="1">
|
14 |
+
<key name="title"/>
|
15 |
+
<key name="labelShow"/>
|
16 |
+
<key name="labelHide"/>
|
17 |
+
</gutenberg-block>
|
18 |
+
</gutenberg-blocks>
|
19 |
+
<admin-texts>
|
20 |
+
<key name="lwptoc_general">
|
21 |
+
<key name="title"/>
|
22 |
+
<key name="labelShow"/>
|
23 |
+
<key name="labelHide"/>
|
24 |
+
</key>
|
25 |
+
</admin-texts>
|
26 |
+
</wpml-config>
|