WordPress Custom Hook with Class method

You can use an anonymous function with PHP’s use statement like so: function mycars($mycarsclass){ $args = array( ‘car1’ => ‘Volvo’, ‘car2’ => ‘Toyota’ ); $mycarsclass->add_node($args); } add_action(‘mycarsaction’, function () use ($mycarsclass) { mycars($mycarsclass); }); do_action(‘mycarsaction’); or declare a separate function and pass that: function mycars($mycarsclass){ $args = array( ‘car1’ => ‘Volvo’, ‘car2’ => ‘Toyota’ ); … Read more

Call to “admin_notices” hook from a static method

Issue got solved by doing two things Removed primary calling from /** * Initialize the activation works of the plugin. */ function awraq_activate_plugin() { //removed } register_activation_hook(__FILE__, ‘awraq_activate_plugin’); Added the call to “plugins_loaded” /** * Initialize the plugin. */ function awraq_init_plugin() { if (Init::activate() != TRUE) { deactivate_plugins(plugin_basename(__FILE__)); //added below Notice::error(‘Plugin got Deactivated. Please check … Read more

add_action in namespace not working

Before going too far down this path I would suggest that you familiarize yourself with PHP name resolution rules. To answer your actual question – When you namespace functions, the fully qualified name of those functions includes the namespace. In your example, you have defined two functions: \myPlugin\add_activation_notice and \myPlugin\activation_notice. When calling either of these … Read more

Get options from database using php class

If you have registered your option without setting the fourth parameter $autoload to no your calls to get_option will not trigger any extra database call because all aotoload options are stored in the cache when the site is loaded. To test it add … define( ‘WP_DEBUG’, TRUE ); define( ‘SAVEQUERIES’, TRUE ); … to your … Read more

changes after I save a post

I would handle this with a shortcode myself. Something like this in your functions.php: function wpa_85620_calculator_shortcode( $atts ) { extract( shortcode_atts( array( ‘key’ => ‘wr4nht4qbp’, ‘width’ => 800, ‘height’ => 800 ), $atts ) ); return sprintf( ‘<object data=”https://www.desmos.com/calculator/%s” width=”%d” height=”%d”></object>’, $key, $width, $height ); } add_shortcode( ‘calculator’, ‘wpa_85620_calculator_shortcode’ ); In your post/page: [calculator] or … Read more

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