There is a plugin I have installed that loads a metabox of an array ($requirements
) list of items in edit post.
When I print_r
the plugin's array it shows:
Array
(
[item1] => Array
(
[status] => 1
[label] => Excerpt has text
[value] => 1
[rule] => only_display
[type] => simple
)
[item2] => Array
(
[status] =>
[label] => Between 100 and 600 words
[value] => Array
(
[0] => 100
[1] => 600
)
[rule] => block
[type] => counter
)
)
I want to change the array and replace with my own array from within the functions.php on editing the post.
The Plugin's Class looks something like:
class MY_Checklist extends MY_Module
{
/**
* List of requirements, filled with instances of requirement classes.
* The list is indexed by post types.
*
* @var array
*/
protected $requirements = [];
/**
* List of post types which supports checklist
*
* @var array
*/
protected $post_types = [];
/**
* Instace for the module
*
* @var stdClass
*/
public $module;
/**
* Construct the MY_Checklist class
*/
public function __construct()
{
//.....
}
public function display_meta_box($post)
{
$requirements = []; //Array I want to change with my own
$requirements = apply_filters('my_checklist_requirement_list', $requirements, $post) // . <--- Array I want to change with my own
}
}
This is as far as I've gotten in my function.php and I am not sure what I am doing.
add_action( 'load-edit.php', 'change_checklist_array' );
function change_checklist_array() {
class MY_NEW_Checklist extends MY_Checklist {
function display_meta_box( $post ) {
$my_new_array = "...";
}
}
}
There is a plugin I have installed that loads a metabox of an array ($requirements
) list of items in edit post.
When I print_r
the plugin's array it shows:
Array
(
[item1] => Array
(
[status] => 1
[label] => Excerpt has text
[value] => 1
[rule] => only_display
[type] => simple
)
[item2] => Array
(
[status] =>
[label] => Between 100 and 600 words
[value] => Array
(
[0] => 100
[1] => 600
)
[rule] => block
[type] => counter
)
)
I want to change the array and replace with my own array from within the functions.php on editing the post.
The Plugin's Class looks something like:
class MY_Checklist extends MY_Module
{
/**
* List of requirements, filled with instances of requirement classes.
* The list is indexed by post types.
*
* @var array
*/
protected $requirements = [];
/**
* List of post types which supports checklist
*
* @var array
*/
protected $post_types = [];
/**
* Instace for the module
*
* @var stdClass
*/
public $module;
/**
* Construct the MY_Checklist class
*/
public function __construct()
{
//.....
}
public function display_meta_box($post)
{
$requirements = []; //Array I want to change with my own
$requirements = apply_filters('my_checklist_requirement_list', $requirements, $post) // . <--- Array I want to change with my own
}
}
This is as far as I've gotten in my function.php and I am not sure what I am doing.
add_action( 'load-edit.php', 'change_checklist_array' );
function change_checklist_array() {
class MY_NEW_Checklist extends MY_Checklist {
function display_meta_box( $post ) {
$my_new_array = "...";
}
}
}
OK, so you’re trying to create your own class that is extending the class from plugin. The problem is that the plugin won’t use your class, so you’d have to modify the plugin.
On the other hand, if you take a closer look at that class:
public function display_meta_box($post)
{
$requirements = []; //Array I want to change with my own
$requirements = apply_filters('my_checklist_requirement_list', $requirements, $post) // . <--- Array I want to change with my own
}
you’ll see, that there is my_checklist_requirement_list
filter in there and you can use it.
So all you need to do is to put this in your functions.php:
add_filter( 'my_checklist_requirement_list', function( $requirements, $post ) {
$requirements = array( ... );
return $requirements;
}, 10, 2 );
my_checklist_requirement_list
. You can read how filters work here: developer.wordpress/plugins/hooks/filters – Jacob Peattie Commented Feb 27, 2019 at 4:05add_filter(my_checklist_requirement_list, change_checklist_array)
within my action or something? – samjco-com Commented Feb 27, 2019 at 4:13