Blocks
2 weeks ago
Traits
2 weeks ago
CFF_About_Us.php
2 weeks ago
CFF_Admin.php
2 weeks ago
CFF_Admin_Notices.php
2 weeks ago
CFF_Callout.php
2 weeks ago
CFF_Global_Settings.php
2 weeks ago
CFF_Install_Skin.php
2 weeks ago
CFF_New_User.php
2 weeks ago
CFF_Notifications.php
2 weeks ago
CFF_Onboarding_Wizard.php
2 weeks ago
CFF_Support.php
2 weeks ago
CFF_Support_Tool.php
2 weeks ago
CFF_Upgrader.php
2 weeks ago
CFF_oEmbeds.php
2 weeks ago
index.php
2 weeks ago
CFF_Admin.php
273 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * CFF_Admin plugin. |
| 5 | * |
| 6 | * Contains everything about the Admin area |
| 7 | * |
| 8 | * @since 2.19 |
| 9 | */ |
| 10 | |
| 11 | namespace CustomFacebookFeed\Admin; |
| 12 | |
| 13 | use CustomFacebookFeed\Builder\CFF_Feed_Builder; |
| 14 | |
| 15 | if (! defined('ABSPATH')) { |
| 16 | exit; // Exit if accessed directly |
| 17 | } |
| 18 | |
| 19 | |
| 20 | class CFF_Admin |
| 21 | { |
| 22 | /** |
| 23 | * Admin constructor |
| 24 | * |
| 25 | * @since 2.19 |
| 26 | */ |
| 27 | public function __construct() |
| 28 | { |
| 29 | $this->admin_hook(); |
| 30 | $this->register_assets(); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * Admin Hooks + Enqueue |
| 36 | * |
| 37 | * @since 2.19 |
| 38 | */ |
| 39 | protected function admin_hook() |
| 40 | { |
| 41 | // Adding Dashboard Menu |
| 42 | add_action('admin_menu', array( $this, 'register_dashboard_menus' ), 9); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | * Register CFF dashboard Menus. |
| 48 | * |
| 49 | * @since 2.19 |
| 50 | */ |
| 51 | public function register_dashboard_menus() |
| 52 | { |
| 53 | $notice = ''; |
| 54 | if (\cff_main()->cff_error_reporter->are_critical_errors()) { |
| 55 | $notice = ' <span class="cff-notice-alert"><span>!</span></span>'; |
| 56 | } |
| 57 | |
| 58 | $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options'; |
| 59 | $cap = apply_filters('cff_settings_pages_capability', $cap); |
| 60 | |
| 61 | $sbi_notifications = new CFF_Notifications(); |
| 62 | $notifications = $sbi_notifications->get(); |
| 63 | |
| 64 | $notice_bubble = ''; |
| 65 | if (empty($notice) && ! empty($notifications) && is_array($notifications)) { |
| 66 | $notice_bubble = ' <span class="cff-notice-alert"><span>' . count($notifications) . '</span></span>'; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | $callout = CFF_Callout::print_callout_ob_html('side-menu'); |
| 71 | $print_callout = $callout !== false ? $callout : ''; |
| 72 | |
| 73 | |
| 74 | add_menu_page( |
| 75 | 'Facebook Feed', |
| 76 | 'Facebook Feed' . $notice . $notice_bubble . $print_callout, |
| 77 | $cap, |
| 78 | 'cff-top', |
| 79 | 'cff_settings_page' |
| 80 | ); |
| 81 | |
| 82 | add_submenu_page( |
| 83 | 'cff-top', |
| 84 | __('Upgrade to Pro', 'custom-facebook-feed'), |
| 85 | __('<span class="cff_get_pro">Upgrade to Pro</span>', 'custom-facebook-feed'), |
| 86 | $cap, |
| 87 | 'https://smashballoon.com/custom-facebook-feed/facebook-lite-upgrade/?utm_campaign=facebook-free&utm_source=menu-link&utm_medium=upgrade-link&utm_content=UpgradeToPro', |
| 88 | '' |
| 89 | ); |
| 90 | if (version_compare(PHP_VERSION, '7.4.0') >= 0 && !is_plugin_active('feeds-for-tiktok/feeds-for-tiktok.php') && !is_plugin_active('tiktok-feeds-pro/tiktok-feeds-pro.php')) { |
| 91 | add_submenu_page( |
| 92 | 'cff-top', |
| 93 | __('TikTok Feeds', 'custom-facebook-feed') . '<span class="cff-notice-alert"><span>New!</span> </span></span>', |
| 94 | '<span class="cff_get_tiktok">' . __('TikTok Feeds', 'custom-facebook-feed') . '</span>' . '<span class="cff-notice-alert cff-new-indicator"><span>New!</span></span>', |
| 95 | $cap, |
| 96 | 'admin.php?page=sbtt', |
| 97 | '' |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | // Show a Reviews plugin menu item if it isn't already installed |
| 102 | if (!is_plugin_active('reviews-feed/sb-reviews.php') && !is_plugin_active('reviews-feed-pro/sb-reviews-pro.php') && current_user_can('activate_plugins') && current_user_can('install_plugins')) { |
| 103 | add_submenu_page( |
| 104 | 'cff-top', |
| 105 | __('Reviews Feed', 'custom-facebook-feed'), |
| 106 | '<span class="cff_get_sbr">' . __('Reviews Feed', 'custom-facebook-feed'), |
| 107 | $cap, |
| 108 | 'admin.php?page=sbr', |
| 109 | '' |
| 110 | ); |
| 111 | } |
| 112 | |
| 113 | // Show a Instagram plugin menu item if it isn't already installed |
| 114 | if (!is_plugin_active('instagram-feed/instagram-feed.php') && !is_plugin_active('instagram-feed-pro/instagram-feed.php') && current_user_can('activate_plugins') && current_user_can('install_plugins')) { |
| 115 | add_submenu_page( |
| 116 | 'cff-top', |
| 117 | __('Instagram Feed', 'custom-facebook-feed'), |
| 118 | '<span class="cff_get_sbi">' . __('Instagram Feed', 'custom-facebook-feed') . '</span>', |
| 119 | $cap, |
| 120 | 'admin.php?page=cff-top&tab=more', |
| 121 | '' |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | // Show a Twitter plugin menu item if it isn't already installed |
| 126 | if (!is_plugin_active('custom-twitter-feeds/custom-twitter-feed.php') && !is_plugin_active('custom-twitter-feeds-pro/custom-twitter-feed.php') && current_user_can('activate_plugins') && current_user_can('install_plugins')) { |
| 127 | add_submenu_page( |
| 128 | 'cff-top', |
| 129 | __('Twitter Feed', 'custom-facebook-feed'), |
| 130 | '<span class="cff_get_ctf">' . __('Twitter Feed', 'custom-facebook-feed') . '</span>', |
| 131 | $cap, |
| 132 | 'admin.php?page=cff-top&tab=more', |
| 133 | '' |
| 134 | ); |
| 135 | } |
| 136 | |
| 137 | // Show a YouTube plugin menu item if it isn't already installed |
| 138 | if (!is_plugin_active('feeds-for-youtube/youtube-feed.php') && !is_plugin_active('youtube-feed-pro/youtube-feed.php') && current_user_can('activate_plugins') && current_user_can('install_plugins')) { |
| 139 | add_submenu_page( |
| 140 | 'cff-top', |
| 141 | __('YouTube Feed', 'custom-facebook-feed'), |
| 142 | '<span class="cff_get_yt">' . __('YouTube Feed', 'custom-facebook-feed') . '</span>', |
| 143 | $cap, |
| 144 | 'admin.php?page=cff-top&tab=more', |
| 145 | '' |
| 146 | ); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Register Assets |
| 152 | * |
| 153 | * @since 2.19 |
| 154 | */ |
| 155 | public function register_assets() |
| 156 | { |
| 157 | add_action('admin_enqueue_scripts', array( $this, 'enqueue_styles_assets' )); |
| 158 | add_action('admin_enqueue_scripts', array( $this, 'enqueue_scripts_assets' )); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | |
| 163 | /** |
| 164 | * Enqueue & Register Styles |
| 165 | * |
| 166 | * @since 2.19 |
| 167 | */ |
| 168 | public function enqueue_styles_assets() |
| 169 | { |
| 170 | wp_register_style( |
| 171 | 'custom_wp_admin_css', |
| 172 | CFF_PLUGIN_URL . 'admin/assets/css/cff-admin-style.css', |
| 173 | false, |
| 174 | CFFVER |
| 175 | ); |
| 176 | wp_enqueue_style('custom_wp_admin_css'); |
| 177 | wp_enqueue_style( |
| 178 | 'cff-font-awesome', |
| 179 | 'https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css', |
| 180 | array(), |
| 181 | '4.5.0' |
| 182 | ); |
| 183 | wp_enqueue_style('wp-color-picker'); |
| 184 | } |
| 185 | |
| 186 | |
| 187 | /** |
| 188 | * Enqueue & Register Scripts |
| 189 | * |
| 190 | * @since 2.19 |
| 191 | */ |
| 192 | public function enqueue_scripts_assets() |
| 193 | { |
| 194 | // Declare color-picker as a dependency |
| 195 | wp_enqueue_script( |
| 196 | 'cff_admin_script', |
| 197 | CFF_PLUGIN_URL . 'admin/assets/js/cff-admin-scripts.js', |
| 198 | false, |
| 199 | CFFVER |
| 200 | ); |
| 201 | |
| 202 | wp_localize_script('cff_admin_script', 'cffA', array( |
| 203 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 204 | 'cff_nonce' => wp_create_nonce('cff_nonce') |
| 205 | )); |
| 206 | |
| 207 | // SMASH-1378 A11Y-004: the cross-plugin "install this plugin" modal is |
| 208 | // opened from the CFF admin submenu items (Instagram / Reviews / YouTube / |
| 209 | // Twitter Feed) on these pages, NOT inside the feed builder. The shared |
| 210 | // focus-trap script is otherwise only enqueued on the builder/settings |
| 211 | // pages, so without this it never engages the modal on the pages where it |
| 212 | // actually appears. The script is framework-agnostic, guards against a |
| 213 | // missing dialog (no-op when no role="dialog" is present), and is safe to |
| 214 | // load globally on CFF admin screens. wp_enqueue_script de-dupes by handle, |
| 215 | // so this will not double-load on the builder page. |
| 216 | if (! wp_script_is('cff-popup-focus-trap', 'enqueued')) { |
| 217 | wp_enqueue_script( |
| 218 | 'cff-popup-focus-trap', |
| 219 | CFF_PLUGIN_URL . 'admin/builder/assets/js/popup-focus-trap.js', |
| 220 | array(), |
| 221 | CFFVER, |
| 222 | true |
| 223 | ); |
| 224 | } |
| 225 | $strings = array( |
| 226 | 'addon_activate' => esc_html__('Activate', 'custom-facebook-feed'), |
| 227 | 'addon_activated' => esc_html__('Activated', 'custom-facebook-feed'), |
| 228 | 'addon_active' => esc_html__('Active', 'custom-facebook-feed'), |
| 229 | 'addon_deactivate' => esc_html__('Deactivate', 'custom-facebook-feed'), |
| 230 | 'addon_inactive' => esc_html__('Inactive', 'custom-facebook-feed'), |
| 231 | 'addon_install' => esc_html__('Install Addon', 'custom-facebook-feed'), |
| 232 | 'addon_error' => esc_html__('Could not install addon. Please download from smashballoon.com and install manually.', 'custom-facebook-feed'), |
| 233 | 'plugin_error' => esc_html__('Could not install a plugin. Please download from WordPress.org and install manually.', 'custom-facebook-feed'), |
| 234 | 'addon_search' => esc_html__('Searching Addons', 'custom-facebook-feed'), |
| 235 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 236 | 'cancel' => esc_html__('Cancel', 'custom-facebook-feed'), |
| 237 | 'close' => esc_html__('Close', 'custom-facebook-feed'), |
| 238 | 'nonce' => wp_create_nonce('cff-admin'), |
| 239 | 'almost_done' => esc_html__('Almost Done', 'custom-facebook-feed'), |
| 240 | 'oops' => esc_html__('Oops!', 'custom-facebook-feed'), |
| 241 | 'ok' => esc_html__('OK', 'custom-facebook-feed'), |
| 242 | 'plugin_install_activate_btn' => esc_html__('Install and Activate', 'custom-facebook-feed'), |
| 243 | 'plugin_install_activate_confirm' => esc_html__('needs to be installed and activated to import its forms. Would you like us to install and activate it for you?', 'custom-facebook-feed'), |
| 244 | 'plugin_activate_btn' => esc_html__('Activate', 'custom-facebook-feed'), |
| 245 | 'oembed_connectionURL' => cffGetOembedConnectionUrl(), |
| 246 | 'smashPlugins' => CFF_Feed_Builder::get_smashballoon_plugins_info() |
| 247 | |
| 248 | ); |
| 249 | $strings = apply_filters('cff_admin_strings', $strings); |
| 250 | |
| 251 | wp_localize_script( |
| 252 | 'cff_admin_script', |
| 253 | 'cff_admin', |
| 254 | $strings |
| 255 | ); |
| 256 | if (!wp_script_is('jquery-ui-draggable')) { |
| 257 | wp_enqueue_script( |
| 258 | array( |
| 259 | 'jquery', |
| 260 | 'jquery-ui-core', |
| 261 | 'jquery-ui-draggable' |
| 262 | ) |
| 263 | ); |
| 264 | } |
| 265 | wp_enqueue_script( |
| 266 | array( |
| 267 | 'hoverIntent', |
| 268 | 'wp-color-picker' |
| 269 | ) |
| 270 | ); |
| 271 | } |
| 272 | } |
| 273 |