I have a plugin that I want to add a settings links to pointing to the settings page of the plugin.
Do you know where can I see a object oriented example of where do I call the function add_filter?
Right now I have the following but I think I placed this code in the wrong place;
class wpy_meta
{
function __construct()
{
add_action('add_meta_boxes', array($this, 'add_meta_box'));
add_action('save_post', array($this, 'save'));
// This is my line of code. Might be in the wrong place. Is this in the right function?
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'mypluginnotrealname_action_links');
}
}
$wpy_meta = new wpy_meta();
Any links or help is appreciated.
Thank you,
V.
]]>//instantiate the object
$path1 = ABS_CONTROLS_PATH . 'class.admin.myclass.inc';
require_once $path1;
$myclassObj = new myclass();
//Create a hidden page,
//that basically just points to the function and class.
add_submenu_page( "", "Do Something", "", "manage_options", 'admin-myclass-dosomething', array($myclassObj, 'dosomething') );
//Then create a constant for the link
define("CATEGORY_ACTION_DISPLAY", '?page=admin-myclass-dosomething', true);
//Then the link looks like this
https://wp1.localhost/wp-admin/admin.php?page=admin-myclass-dosomething&id=BDBED1D3-2D41-11E3-8485-79F665153CEA
]]>I’m trying to develop my WordPress skills a little. I’ve previously moved some of my functions.php that I use time and time again into a must-use plugin. I’m now trying to make that Object Oriented – with limited success. The code below is an excerpt of my overall code. The first section works perfectly, reducing the excerpt length, but the dashboard tidy doesn’t. Both previously worked as procedural code.
Any help in solving this would really be appreciated. Also, I’m struggling to understand why it is recommended to use the init rather than putting my actions and filters into the constructor. Can anyone explain this for me?
class OOtest
{
public function __construct()
{
add_action( 'wp', array( $this, 'init' ) );
}
public function init()
{
//Tidy up the dashboard
add_action('wp_dashboard_setup', array( $this, 'tidy_dashboard') );
//Edit excerpt length
add_filter('excerpt_length', array( $this, 'custom_excerpt_length') );
}
public function tidy_dashboard()
{
global $wp_meta_boxes, $current_user;
// remove incoming links info for authors or editors
if(in_array('author', $current_user->roles) || in_array('editor', $current_user->roles))
{
unset($wp_meta_boxes['dashboard']['normal ']['core']['dashboard_incoming_links']);
}
// remove the plugins info and news feeds for everyone
//Wordpress Development Blog Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
//Other WordPress News Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
//Quick Press Form
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
//Plugins - Popular, New and Recently updated WordPress Plugins
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
}
// Add custom excerpt length
public function custom_excerpt_length($length)
{ return 55; }
}
$foo = new OOtest;
?>
]]>README file explains details but to give a brief introduction, you can write plugin classes by using annotations in docblocks. It is very easy to create plugins with OOP approach. It is simple and clean.
There are some undocumented parts like Settings API abstraction but I couldn’t wait to get first impressions.
I appreciate your feedbacks.
]]>Thanks in advance.
]]>I’m new to this forum, but not totally new to wordpress. Recently I made https://tour.isme.nl with wordpress, together with a friende of mine.
I have just started as freelance interaction designer, and have been busy with my own new website. I really like designing systems and first thought I would build upon my own simple cms I created last year. But, to implement all the ideas I have, and have a robust cms with all the usual functionalities at the same time, I would be busy for some more months/years I guess.
That’s why I changed my mind: I’ll build my website with an opensource cms like wordpress, so that I have a good system to start with, and have my first version website up and running in a couple of days. Lateron, I might develop the ideas for my own cms or as new plugins. I want to share my ideas, so that you guys can let me know if you think this is the right way to create the system I want:
Do you think it will be possible to develop these ideas in WordPress, or does something like this already exist as a plugin? Or should I continue my own cms building? Let me know what you guys think. Thanks in advance!
Nico
btw: I hope you don’t mind me starting this same discussion in other opensource cms forums like drupal and joomla.
]]>