assets
1 year ago
loader.php
1 year ago
ppf-admin.php
1 year ago
ppf-class.php
1 year ago
ppf-plugin-addon.php
1 year ago
ppf-plugin.php
1 year ago
ppf-settings.php
1 year ago
ppf-subclass.php
1 year ago
ppf-class.php
153 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Base Class |
| 5 | * |
| 6 | * Peter's Plugins Foundation 09 |
| 7 | * |
| 8 | * @package PPF09 |
| 9 | * @author Peter Raschendorfer |
| 10 | * @license GPL2+ |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // Exit if accessed directly |
| 16 | } |
| 17 | |
| 18 | if ( !class_exists( 'PPF09_Class' ) ) { |
| 19 | |
| 20 | |
| 21 | abstract class PPF09_Class { |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * foundation dir |
| 26 | * |
| 27 | * removed in PPF02 |
| 28 | * |
| 29 | * @since PPF01 |
| 30 | * @var string |
| 31 | * @access private |
| 32 | */ |
| 33 | // private $_dir; |
| 34 | |
| 35 | |
| 36 | /** |
| 37 | * Init the Class |
| 38 | * |
| 39 | * @since PPF01 |
| 40 | * @see getInstance |
| 41 | */ |
| 42 | public function __construct() { |
| 43 | |
| 44 | // removed in PPF02 |
| 45 | // $this->_dir = __DIR__; |
| 46 | |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /** |
| 51 | * get foundation directory |
| 52 | * |
| 53 | * @since PPF01 |
| 54 | * @access protected |
| 55 | * @return string |
| 56 | */ |
| 57 | protected function get_foundation_dir() { |
| 58 | |
| 59 | // since PPF02 we have to get the Directory of the Called Class to allow multiple classes based on the same Plugin Foundation |
| 60 | |
| 61 | $rc = new ReflectionClass( get_called_class() ); |
| 62 | return dirname( $rc->getFileName() ) . '/ppf'; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | |
| 67 | /** |
| 68 | * get url for foundation asset file |
| 69 | * |
| 70 | * @since PPF01 |
| 71 | * @access protected |
| 72 | * @param string $dir sub-directory of assets dir (js, css) |
| 73 | * @param string $file filename |
| 74 | * @return string |
| 75 | */ |
| 76 | protected function get_foundation_asset_url( $dir, $file ) { |
| 77 | |
| 78 | return plugins_url() . str_replace( WP_PLUGIN_DIR, '', $this->get_foundation_dir() ) . '/assets/' . $dir . '/' . $file; |
| 79 | |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /** |
| 84 | * get path for foundation asset file |
| 85 | * |
| 86 | * @since PPF01 |
| 87 | * @access protected |
| 88 | * @param string $dir sub-directory of assets dir (js, css) |
| 89 | * @param string $file filename |
| 90 | * @return string |
| 91 | */ |
| 92 | protected function get_foundation_asset_path( $dir, $file ) { |
| 93 | |
| 94 | return plugin_dir_path( $this->get_foundation_dir() ) . 'assets/' . $dir . '/' . $file; |
| 95 | |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /** |
| 100 | * add action |
| 101 | * |
| 102 | * @since PPF01 |
| 103 | * @access public |
| 104 | * @param string $wpaction name of the action to add |
| 105 | * @param int $priority priority - optional - default 10 |
| 106 | * @param int $accepted_args number of arguments the function accepts - optional - default 1 |
| 107 | */ |
| 108 | public function add_action( $wpaction, $priority = 10, $accepted_args = 1 ) { |
| 109 | |
| 110 | add_action( $wpaction, array( $this, 'action_' . $wpaction ), $priority, $accepted_args ); |
| 111 | |
| 112 | } |
| 113 | |
| 114 | |
| 115 | /** |
| 116 | * add multiple actions |
| 117 | * this function does not allow to specify priority and accepted_args |
| 118 | * |
| 119 | * @since PPF01 |
| 120 | * @access public |
| 121 | * @param array $actions array of actions to add |
| 122 | * @see add_action() |
| 123 | */ |
| 124 | public function add_actions( $actions ) { |
| 125 | |
| 126 | foreach ( $actions as $action ) { |
| 127 | |
| 128 | $this->add_action( $action ); |
| 129 | |
| 130 | } |
| 131 | |
| 132 | } |
| 133 | |
| 134 | |
| 135 | /** |
| 136 | * add filter |
| 137 | * |
| 138 | * @since PPF01 |
| 139 | * @access public |
| 140 | * @param string $wpfilter name of the filter to add |
| 141 | * @param int $priority priority - optional - default 10 |
| 142 | * @param int $accepted_args number of arguments the function accepts - optional - default 1 |
| 143 | */ |
| 144 | public function add_filter( $wpfilter, $priority = 10, $accepted_args = 1 ) { |
| 145 | |
| 146 | add_filter( $wpfilter, array( $this, 'filter_' . $wpfilter ), $priority, $accepted_args ); |
| 147 | |
| 148 | } |
| 149 | |
| 150 | |
| 151 | } |
| 152 | |
| 153 | } |