OOP Plugin Development. Including external object

The root of your problem is not object oriented programming, but a fundamental misunderstanding about how PHP handles requests. If this were a Java or a Node application for example, you would start the application on the server, and it would recieve requests, and respond. It’s a continuous active program. As a result, you can … Read more

register child class in another plugin

I question the wisdom of extending a class from another plugin. You have no idea what will happen next time that other plugin gets updated. However, generally speaking you can control when in a hook “queue” a function runs by passing a third parameter– a priority. So pass a priority high enough and your function … Read more

Trying to get logged-in user data inside php class

Once you said is you first time using OOP, I want to say: stop using & before $this: PHP4 died long time ago. Second tip, don’t use global variables, if you can. I know that function like wp_get_current_user use global variable internally, but I hope that in future it will not be so anymore, however … Read more

Ajax with OOP doesn’t work

You need to create a new instance of the class so that your constructor is called and your actions are registered. e.g. you need to add something like $test = new PR_Test; below the definition of PR_Test.

Create hooks based on an array of hook names?

Your proposal is OK – you can see this in action even in the WordPress itself. See admin-ajax.php where you can find this piece of code: // Register core Ajax calls. if ( ! empty( $_GET[‘action’] ) && in_array( $_GET[‘action’], $core_actions_get ) ) add_action( ‘wp_ajax_’ . $_GET[‘action’], ‘wp_ajax_’ . str_replace( ‘-‘, ‘_’, $_GET[‘action’] ), 1 … Read more

PHP5, Inheritance, Singleton – action & filter hook limitations

You don’t have to declare the constructor public, just the action hook function. Example: <?php /* Plugin Name: Singleton Action */ class Singleton_Demo { /** * @static $instance Objekt * @access private; */ private static $_instance = NULL; protected function __construct() {} private final function __clone() {} public static function getInstance() { if ( self::$_instance … Read more

Get the object ID by URL

Try this function: url_to_postid( $url ); The WordPress codex is your friend. A quick Google search could have provided the answer.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)