class-nestedpages.php
| 1 | <?php |
| 2 | // Activate and Check Versions |
| 3 | require_once('class-np-activate.php'); |
| 4 | |
| 5 | // Form Handlers |
| 6 | require_once('class-np-handler-sort.php'); |
| 7 | require_once('class-np-handler-quickedit.php'); |
| 8 | require_once('class-np-handler-quickedit-redirect.php'); |
| 9 | require_once('class-np-handler-newredirect.php'); |
| 10 | require_once('class-np-handler-syncmenu.php'); |
| 11 | require_once('class-np-handler-nesttoggle.php'); |
| 12 | require_once('class-np-handler-gettax.php'); |
| 13 | require_once('class-np-handler-newchild.php'); |
| 14 | |
| 15 | // Required Classes |
| 16 | require_once('class-np-dependencies.php'); |
| 17 | require_once('class-np-pagelisting.php'); |
| 18 | require_once('class-np-newpage.php'); |
| 19 | require_once('class-np-redirects.php'); |
| 20 | require_once('class-np-posttypes.php'); |
| 21 | require_once('class-np-settings.php'); |
| 22 | |
| 23 | /** |
| 24 | * Primary Plugin Class |
| 25 | */ |
| 26 | class NestedPages { |
| 27 | |
| 28 | |
| 29 | public function __construct() |
| 30 | { |
| 31 | $this->init(); |
| 32 | $this->formActions(); |
| 33 | add_action( 'init', array($this, 'listPages') ); |
| 34 | add_action( 'init', array($this, 'addLocalization') ); |
| 35 | add_action( 'admin_init', array($this, 'verifyPostType') ); |
| 36 | add_filter( 'plugin_action_links_' . 'wp-nested-pages/nestedpages.php', array($this, 'settingsLink' ) ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Initialize Plugin |
| 41 | */ |
| 42 | public function init() |
| 43 | { |
| 44 | new NP_Activate; |
| 45 | new NP_Dependencies; |
| 46 | new NP_NewPage; |
| 47 | new NP_Redirects; |
| 48 | new NP_PostTypes; |
| 49 | new NP_Settings; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Page Listing |
| 54 | * @since 1.1.6 - Moved into init due to Multisite bug |
| 55 | */ |
| 56 | public function listPages() |
| 57 | { |
| 58 | new NP_PageListing; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | |
| 63 | /** |
| 64 | * Set Form Actions & Handlers |
| 65 | */ |
| 66 | public function formActions() |
| 67 | { |
| 68 | if ( is_admin() ) { |
| 69 | add_action( 'wp_ajax_npsort', 'nestedpages_sort_handler' ); |
| 70 | add_action( 'wp_ajax_npquickedit', 'nestedpages_quickedit_handler' ); |
| 71 | add_action( 'wp_ajax_npsyncmenu', 'nestedpages_syncmenu_handler' ); |
| 72 | add_action( 'wp_ajax_npnesttoggle', 'nestedpages_nesttoggle_handler' ); |
| 73 | add_action( 'wp_ajax_npquickeditredirect', 'nestedpages_quickedit_redirect_handler' ); |
| 74 | add_action( 'wp_ajax_npnewredirect', 'nestedpages_new_redirect'); |
| 75 | add_action( 'wp_ajax_gettax', 'nestedpages_get_tax' ); |
| 76 | add_action( 'wp_ajax_npnewchild', 'nestedpages_newchild_handler' ); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | |
| 81 | /** |
| 82 | * Localization Domain |
| 83 | */ |
| 84 | public function addLocalization() |
| 85 | { |
| 86 | load_plugin_textdomain('nestedpages', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages' ); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | /** |
| 91 | * Add a link to the settings on the plugin page |
| 92 | */ |
| 93 | public function settingsLink($links) |
| 94 | { |
| 95 | $settings_link = '<a href="options-general.php?page=nested-pages-settings">' . __('Settings') . '</a>'; |
| 96 | array_unshift($links, $settings_link); |
| 97 | return $links; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /** |
| 102 | * Check for the page post type before doing anything |
| 103 | */ |
| 104 | public function verifyPostType() |
| 105 | { |
| 106 | if ( !get_post_type_object( 'page' ) ){ |
| 107 | $plugin = dirname(dirname( __FILE__ ) ) . '/nestedpages.php'; |
| 108 | deactivate_plugins( $plugin ); |
| 109 | wp_die('<p>Nested Pages has been deactivated. This plugin requires the <strong>"page"</strong> post type to be enabled and available for use. Please disable any plugins that may be interfering with this post type and reactivate.</p>','Plugin Activation Error', array( 'response'=>200, 'back_link'=>TRUE ) ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | |
| 114 | } |