Skip to content
This repository was archived by the owner on Dec 4, 2019. It is now read-only.

Commit 15eccb9

Browse files
committed
2.0 Make Post Entities a static submodule
1 parent 528eafa commit 15eccb9

17 files changed

+403
-156
lines changed

plugins/redux-dev/ReduxCore/inc/classes/class.redux_field_descriptor_fields.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct($name, $title, $type, $description = '', $default =
2525
if (!Redux_Descriptor_Types::isValidType($type)) {
2626
throw new Exception('Unknown type ' . $type . ' for option ' . $name);
2727
}
28-
if (!is_string($title)) {
28+
if (!is_string($title) || empty($title)) {
2929
$title = ucfirst($name);
3030
}
3131
$this->options = array(

plugins/redux-extensions/metaboxes/extension_metaboxes.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ public function __construct( $parent ) {
8787

8888
self::$instances[] = &$this;
8989

90-
add_action( 'admin_init', array( $this, 'init_all' ), 0, PHP_INT_MAX );
90+
if (did_action('admin_init') && is_admin()) {
91+
self::init_all();
92+
} else {
93+
add_action( 'admin_init', array( self::class, 'init_all' ), 0, PHP_INT_MAX );
94+
}
9195
//$this->init();
9296
} // __construct()
9397

src/Interfaces/ShortcodeMapper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Tofandel\Core\Interfaces;
1010

1111

12+
use Tofandel\Core\Objects\ShortcodeDescriptor;
1213
use Tofandel\Core\Objects\ShortcodeParameter;
1314

1415
interface ShortcodeMapper {
@@ -22,10 +23,10 @@ public static function shouldMap();
2223
/**
2324
* Handles the mapping logic
2425
*
25-
* @param array $info
26+
* @param ShortcodeDescriptor $info
2627
*
2728
*/
28-
public static function map( array $info );
29+
public static function map( ShortcodeDescriptor $info );
2930

3031
/**
3132
* Handles the parameter mapping logic

src/Interfaces/WP_Mapped_Shortcode.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,14 @@ public static function mapping();
2424

2525
public static function setInfo( $name, $description = '', $category = '', $icon = '' );
2626

27-
public static function setParam( ShortcodeParameter $param );
27+
/**
28+
* @param string $name
29+
* @param string $title
30+
* @param string $type ShortcodeParametersTypes::const
31+
* @param string $description
32+
* @param string $category
33+
*
34+
* @return ShortcodeParameter
35+
*/
36+
public static function addParameter( $name, $title, $type, $description = '', $category = '' );
2837
}

src/Interfaces/WP_Post_Entity.php

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,59 +19,5 @@
1919
* @property $post_parent
2020
*/
2121
interface WP_Post_Entity {
22-
/**
23-
* @param mixed $post_or_slug
24-
* @param bool $create
25-
*
26-
* @throws \Exception
27-
*/
28-
public function setPost( $post_or_slug = false, $create = false );
29-
3022
public function postType();
31-
32-
/**
33-
* @param int $ID
34-
*/
35-
public function setID( $ID );
36-
37-
public function setOverride( $name, $val );
38-
39-
/**
40-
* @return bool
41-
*/
42-
public function isCreated();
43-
44-
/**
45-
* @param $name
46-
*
47-
* @return mixed
48-
*/
49-
public function get( $name );
50-
51-
/**
52-
* @param $name
53-
* @param $value
54-
*
55-
*/
56-
public function set( $name, $value );
57-
58-
public function save();
59-
60-
public function delete( $force = true );
61-
62-
/**
63-
* @return static
64-
*/
65-
public function duplicate();
66-
67-
/**
68-
* @param \WP_User $user
69-
*/
70-
public function reassign( $user );
71-
72-
/**
73-
* @param \WP_Post $post
74-
* @param int $new_author
75-
*/
76-
public function reassign_recursive( $post, $new_author );
7723
}

src/Modules/LicenceManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function deactivated() {
259259
* The hooks of the submodule
260260
*/
261261
public function actionsAndFilters() {
262-
add_action( 'wpp_redux_' . $this->parent->getReduxOptName() . '_config', [ $this, 'addSection' ], 50, 1 );
262+
add_action( 'wpp/redux/' . $this->parent->getReduxOptName() . '/config', [ $this, 'addSection' ], 50, 1 );
263263
}
264264

265265
public function addSection( ReduxFramework $framework ) {
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Adrien
5+
* Date: 20/11/2018
6+
* Time: 16:37
7+
*/
8+
9+
namespace Tofandel\Core\Objects;
10+
11+
use Tofandel\Core\ShortcodeMappers\VC_Mapper;
12+
13+
class ShortcodeDescriptor {
14+
protected $name;
15+
16+
protected $title;
17+
protected $description;
18+
protected $category;
19+
protected $icon;
20+
21+
/**
22+
* @var ShortcodeParameter[]
23+
*/
24+
protected $parameters = array();
25+
26+
protected $currentParam;
27+
28+
protected $moreOptions;
29+
30+
/**
31+
* ShortcodeDescriptor constructor.
32+
*
33+
* @param $class
34+
*/
35+
public function __construct( $class ) {
36+
ShortcodeParameter::$autoOrder = 0;
37+
$this->name = call_user_func( array( $class, 'getName' ) );
38+
}
39+
40+
public function getName() {
41+
return $this->name;
42+
}
43+
44+
public function setInfo( $title, $description = '', $category = '', $icon = '' ) {
45+
$this->title = $title;
46+
$this->description = $description;
47+
$this->category = $category;
48+
$this->icon = $icon;
49+
}
50+
51+
public function getTitle() {
52+
return $this->title;
53+
}
54+
55+
public function getDescription() {
56+
return $this->description;
57+
}
58+
59+
public function getCategory() {
60+
return $this->category;
61+
}
62+
63+
public function getIcon() {
64+
return $this->icon;
65+
}
66+
67+
public function __get( $name ) {
68+
return isset( $this->moreOptions[ $name ] ) ? $this->moreOptions[ $name ] : null;
69+
}
70+
71+
public function __set( $name, $value ) {
72+
$this->moreOptions[ $name ] = $value;
73+
}
74+
75+
public function __isset( $name ) {
76+
return isset( $this->moreOptions[ $name ] );
77+
}
78+
79+
public function addHTMLParameters() {
80+
global $WPlusPlusCore;
81+
$this->addParameter( 'html_id', __( 'ID', $WPlusPlusCore->getTextDomain() ), ShortcodeParametersTypes::TEXT, __( 'The HTML id of the element', $WPlusPlusCore->getTextDomain() ), __( 'HTML Attributes', $WPlusPlusCore->getTextDomain() ) );
82+
$this->addParameter( 'html_class', __( 'Class', $WPlusPlusCore->getTextDomain() ), ShortcodeParametersTypes::TEXT, __( 'The HTML class you want to add to the element', $WPlusPlusCore->getTextDomain() ), __( 'HTML Attributes', $WPlusPlusCore->getTextDomain() ) );
83+
return $this;
84+
}
85+
86+
/**
87+
* @param string|ShortcodeParameter $name
88+
* @param string $title
89+
* @param string $type ShortcodeParametersTypes::const
90+
* @param string $description
91+
* @param string $category
92+
*
93+
* @return ShortcodeParameter
94+
*/
95+
public function addParameter( $name, $title = '', $type = '', $description = '', $category = '' ) {
96+
if ( is_a( $name, ShortcodeParameter::class ) ) {
97+
$this->parameters[ $name->getName() ] = $name;
98+
} else {
99+
$this->parameters[ $name ] = new ShortcodeParameter( $name, $title, $type, $description, $category );
100+
$this->currentParam = $name;
101+
}
102+
103+
return $this->parameters[ $name ];
104+
}
105+
106+
public function parseRequest( $req ) {
107+
$parsed_req = array();
108+
foreach ( $req as $k => $v ) {
109+
if ( isset( $this->parameters[ $k ] ) ) {
110+
$parsed_req[ $k ] = $v;
111+
}
112+
}
113+
114+
return $parsed_req;
115+
}
116+
117+
/**
118+
* Selects and returns a field or the current field
119+
*
120+
* @param string $paramName
121+
*
122+
* @return mixed|null
123+
*/
124+
public function param( $paramName = '' ) {
125+
if ( ! empty( $paramName ) ) {
126+
$this->currentParam = $paramName;
127+
}
128+
129+
if ( isset( $this->parameters[ $this->currentParam ] ) ) {
130+
return $this->parameters[ $this->currentParam ];
131+
} else {
132+
return null;
133+
}
134+
}
135+
136+
public function removeParameter( $name ) {
137+
unset( $this->parameters[ $name ] );
138+
}
139+
140+
protected function sortFields() {
141+
usort( $this->parameters, function ( ShortcodeParameter $item1, ShortcodeParameter $item2 ) {
142+
return $item1->getOrder() <=> $item2->getOrder();
143+
} );
144+
}
145+
146+
/**
147+
* @var ShortcodeMapper[]
148+
*/
149+
static $mappers;
150+
151+
/**
152+
* @return ShortcodeMapper[]
153+
*/
154+
public static function initMappers() {
155+
static $mappers;
156+
157+
if ( ! isset( $mappers ) ) {
158+
self::$mappers = apply_filters( 'wpp_shortcode_mappers', array( VC_Mapper::class ) );
159+
foreach ( self::$mappers as $mapper ) {
160+
if ( $mapper::shouldMap() ) {
161+
$mappers[] = $mapper;
162+
}
163+
}
164+
}
165+
166+
return $mappers;
167+
}
168+
}

src/Objects/ShortcodeMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ abstract public static function shouldMap();
2020
/**
2121
* Handles the mapping logic
2222
*
23-
* @param array $info
23+
* @param ShortcodeDescriptor $info
2424
*
2525
*/
26-
abstract public static function map( array $info );
26+
abstract public static function map( ShortcodeDescriptor $info );
2727

2828
/**
2929
* Handles the parameter mapping logic

0 commit comments

Comments
 (0)