php - Wordpress Define Variable Plugin -
php - Wordpress Define Variable Plugin -
i'm attempting create plugin site in wordpress both practice , execution. in plugin variety of files. want define plugin directory constant use:
define('custom_editing__url', plugin_dir_url(__file__));
when include:
//folders define('widgets', custom_editing__url . 'widgets/'); require_once(widgets . 'widgets.php');
i'm able file widgets.php
, when phone call within of file:
echo custom_editing__url;
i custom_editing__url. want http://www.example.com/widgets/widget.php
can explain i'm missing?
edit: more info problem @ hand.
right have figured out widgets.php not accepting defined variables. example... calling file able create widget using format of:
class foo_widget extends wp_widget { // content }
but widgets.php file cannot resolve find wp_widget.
so answer. don't have actual documentation explain it. copied of elements akismet plugin work way needed to.
define( 'custom_editing__url', plugin_dir_url( __file__ ) ); define( 'custom_editing__dir', plugin_dir_path( __file__ ) ); require_once( custom_editing__dir . 'class.custom-editing-widget.php' ); require_once( custom_editing__dir . 'class.custom-editing.php'); register_activation_hook( __file__, array( 'customediting', 'plugin_activation' ) ); register_deactivation_hook( __file__, array( 'customediting', 'plugin_deactivation' ) ); add_action( 'init', array( 'customediting', 'init' ) );
in file class.custom-editing.php
create class these base of operations parameters:
class customediting { private static $initiated = false; public function __construct(){ } public static function init() { if ( ! self::$initiated ) { self::init_hooks(); } } private static function init_hooks() { self::$initiated = true; } }
this solves base of operations errors created activation hooks believe. if can explain parts in improve terms appreciated, don't understand why worked , had didn't.
php wordpress variables constants
Comments
Post a Comment