Dependencies.php
188 lines
| 1 | <?php |
| 2 | namespace NestedPages\Activation; |
| 3 | |
| 4 | use NestedPages\Entities\PostType\PostTypeRepository; |
| 5 | use NestedPages\Entities\PluginIntegration\IntegrationFactory; |
| 6 | use NestedPages\Config\SettingsRepository; |
| 7 | use NestedPages\Helpers; |
| 8 | |
| 9 | /** |
| 10 | * Plugin JS & CSS Dependencies |
| 11 | */ |
| 12 | class Dependencies |
| 13 | { |
| 14 | /** |
| 15 | * Plugin Directory |
| 16 | */ |
| 17 | private $plugin_dir; |
| 18 | |
| 19 | /** |
| 20 | * Plugin Version |
| 21 | */ |
| 22 | private $plugin_version; |
| 23 | |
| 24 | /** |
| 25 | * Post Type Repository |
| 26 | */ |
| 27 | private $post_type_repo; |
| 28 | |
| 29 | /** |
| 30 | * Settings Repository |
| 31 | */ |
| 32 | private $settings; |
| 33 | |
| 34 | /** |
| 35 | * Integrations |
| 36 | */ |
| 37 | private $integrations; |
| 38 | |
| 39 | public function __construct() |
| 40 | { |
| 41 | $this->post_type_repo = new PostTypeRepository; |
| 42 | $this->integrations = new IntegrationFactory; |
| 43 | $this->settings = new SettingsRepository; |
| 44 | $this->setPluginVersion(); |
| 45 | add_action( 'admin_enqueue_scripts', [$this, 'styles']); |
| 46 | add_action( 'admin_enqueue_scripts', [$this, 'scripts']); |
| 47 | add_action( 'admin_enqueue_scripts', [$this, 'settingsScripts']); |
| 48 | $this->plugin_dir = Helpers::plugin_url(); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Set the Plugin Version |
| 53 | */ |
| 54 | private function setPluginVersion() |
| 55 | { |
| 56 | global $np_version; |
| 57 | $this->plugin_version = $np_version; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Admin Styles |
| 62 | */ |
| 63 | public function styles() |
| 64 | { |
| 65 | wp_enqueue_style( |
| 66 | 'nestedpages', |
| 67 | $this->plugin_dir . '/assets/css/nestedpages.css', |
| 68 | [], |
| 69 | $this->plugin_version |
| 70 | ); |
| 71 | if ( $this->integrations->plugins->acf->installed ) wp_enqueue_style('acf-input'); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Admin Scripts required by plugin |
| 76 | * Only Loads on the Nested Pages screen |
| 77 | */ |
| 78 | public function scripts() |
| 79 | { |
| 80 | $screen = get_current_screen(); |
| 81 | global $np_page_params; |
| 82 | global $np_env; |
| 83 | global $wp_post_statuses; |
| 84 | $settings_page = ( strpos($screen->id, 'nested-pages-settings') ) ? true : false; |
| 85 | if ( strpos( $screen->id, 'nestedpages' ) || $settings_page ) : |
| 86 | wp_enqueue_script('suggest'); |
| 87 | wp_enqueue_script('jquery-ui-core'); |
| 88 | wp_enqueue_script('jquery-ui-sortable'); |
| 89 | wp_enqueue_script('jquery-ui-datepicker'); |
| 90 | wp_enqueue_script( |
| 91 | 'ui-touch-punch', |
| 92 | $this->plugin_dir . '/assets/js/lib/jquery.ui.touch-punch.min.js', |
| 93 | ['jquery', 'jquery-ui-sortable'], |
| 94 | $this->plugin_version |
| 95 | ); |
| 96 | wp_enqueue_script( |
| 97 | 'nested-sortable', |
| 98 | $this->plugin_dir . '/assets/js/lib/jquery.mjs.nestedSortable.js', |
| 99 | ['jquery', 'jquery-ui-sortable'], |
| 100 | $this->plugin_version |
| 101 | ); |
| 102 | if ( $np_env == 'dev' ){ |
| 103 | wp_enqueue_script( |
| 104 | 'nestedpages', |
| 105 | $this->plugin_dir . '/assets/js/nestedpages.js', |
| 106 | ['jquery'], |
| 107 | $this->plugin_version |
| 108 | ); |
| 109 | } else { |
| 110 | wp_enqueue_script( |
| 111 | 'nestedpages', |
| 112 | $this->plugin_dir . '/assets/js/nestedpages.min.js', |
| 113 | ['jquery'], |
| 114 | $this->plugin_version |
| 115 | ); |
| 116 | } |
| 117 | $localized_data = [ |
| 118 | 'np_nonce' => wp_create_nonce( 'nestedpages-nonce' ), |
| 119 | 'expand_text' => __('Expand All', 'wp-nested-pages'), |
| 120 | 'collapse_text' => __('Collapse All', 'wp-nested-pages'), |
| 121 | 'show_hidden' => __('Show Hidden', 'wp-nested-pages'), |
| 122 | 'hide_hidden' => __('Hide Hidden', 'wp-nested-pages'), |
| 123 | 'add_link' => __('Add Link', 'wp-nested-pages'), |
| 124 | 'add_child_link' => __('Add Child Link', 'wp-nested-pages'), |
| 125 | 'title' => __('Title', 'wp-nested-pages'), |
| 126 | 'quick_edit' => __('Quick Edit', 'wp-nested-pages'), |
| 127 | 'page_title' => __('Page Title', 'wp-nested-pages'), |
| 128 | 'view' => __('View', 'wp-nested-pages'), |
| 129 | 'add_child_short' => __('Add Child', 'wp-nested-pages'), |
| 130 | 'add_child' => __('Add Child Page', 'wp-nested-pages'), |
| 131 | 'add_child_pages' => __('Add Child Pages', 'wp-nested-pages'), |
| 132 | 'add' => __('Add', 'wp-nested-pages'), |
| 133 | 'add_page' => __('Add Page', 'wp-nested-pages'), |
| 134 | 'add_pages' => __('Add Pages', 'wp-nested-pages'), |
| 135 | 'add_multiple' => __('Add Multiple', 'wp-nested-pages'), |
| 136 | 'trash_confirm' => __('Are you sure you would like to empty the trash? This action is not reversible.', 'wp-nested-pages'), |
| 137 | 'hidden' => __('Hidden', 'wp-nested-pages'), |
| 138 | 'bulk_actions' => __('Bulk Actions', 'wp-nested-pages'), |
| 139 | 'link_delete_confirmation' => __('Your selection includes link items, which cannot be recovered after deleting. Would you like to continue? (Other items are moved to the trash)', 'wp-nested-pages'), |
| 140 | 'link_delete_confirmation_singular' => __('Are you sure you would like to delete this item? This action is not reversible.', 'wp-nested-pages'), |
| 141 | 'delete' => __('Delete', 'wp-nested-pages'), |
| 142 | 'trash_delete_links' => __('Trash Posts and Delete Links', 'wp-nested-pages'), |
| 143 | 'manual_menu_sync' => $this->settings->autoMenuDisabled(), |
| 144 | 'manual_order_sync' => $this->settings->autoPageOrderDisabled(), |
| 145 | 'currently_assigned_to' => __('Currently assigned to:', 'wp-nested-pages'), |
| 146 | 'remove' => __('Remove', 'wp-nested-pages'), |
| 147 | 'settings_page' => $settings_page, |
| 148 | 'wpml' => ( $this->integrations->plugins->wpml->installed ) ? true : false, |
| 149 | 'add_translation' => __('Add Translation', 'wp-nested-pages'), |
| 150 | 'edit' => __('Edit', 'wp-nested-pages'), |
| 151 | 'insert_before' => __('Insert Before', 'wp-nested-pages'), |
| 152 | 'insert_after' => __('Insert After', 'wp-nested-pages'), |
| 153 | 'non_indent' => $this->settings->nonIndentEnabled(), |
| 154 | 'private' => __('Private', 'wp-nested-pages'), |
| 155 | 'post_statuses' => $wp_post_statuses, |
| 156 | 'current_page' => ( isset($_GET['page']) ) ? sanitize_text_field($_GET['page']) : null |
| 157 | ]; |
| 158 | $syncmenu = ( get_option('nestedpages_menusync') == 'sync' ) ? true : false; |
| 159 | $localized_data['syncmenu'] = $syncmenu; |
| 160 | $localized_data['post_types'] = $this->post_type_repo->getPostTypesObject(); |
| 161 | if ( isset($np_page_params) && is_array($np_page_params) && array_key_exists($screen->id, $np_page_params) ){ |
| 162 | $localized_data['current_post_type'] = $np_page_params[$screen->id]['post_type']; |
| 163 | } |
| 164 | wp_localize_script( |
| 165 | 'nestedpages', |
| 166 | 'nestedpages', |
| 167 | $localized_data |
| 168 | ); |
| 169 | if ( $this->integrations->plugins->acf->installed ) wp_enqueue_script('acf-input'); |
| 170 | endif; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Settings |
| 175 | */ |
| 176 | public function settingsScripts() |
| 177 | { |
| 178 | $screen = get_current_screen(); |
| 179 | if ( strpos( $screen->id, 'nested-pages-settings' ) ) : |
| 180 | wp_enqueue_script( |
| 181 | 'nestedpages-settings', |
| 182 | $this->plugin_dir . '/assets/js/nestedpages.settings.min.js', |
| 183 | ['jquery'], |
| 184 | $this->plugin_version |
| 185 | ); |
| 186 | endif; |
| 187 | } |
| 188 | } |