Example #1
0
 /**
  * Returns the active status of the importer
  *
  * @return bool
  */
 public static function isActive()
 {
     global $wpdb;
     if (!current_user_can('upload_files') || !PluginInfo::isInstalled('NextGEN Gallery') || !($gallery_count = (int) $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}ngg_gallery`"))) {
         return false;
     }
     return true;
 }
 /**
  * Returns the active status of the importer
  *
  * @return bool
  */
 public static function isActive()
 {
     // Only active if ...
     if (!current_user_can('upload_files') || !PluginInfo::isInstalled('WP Flickr Background') || ($options = get_option(static::WP_OPTION_NAME)) === false || !array_key_exists('galleries', $options) || !is_array($options['galleries']) || count($options['galleries']) == 0) {
         return false;
     }
     return true;
 }
 /**
  * Shutdown callback
  *
  * This callback is used to manage fatal errors, by logging it to a file if possible and
  * providing the user with feedback as to what the error was. This avoids the
  * over-simplistic 500 errors normally generated (provided WP_DEBUG was set to false).
  *
  * NOTE: This will only apply to pf4wp instances. This may de-activate a plugin, leaving
  * only the current instance. The current instance will be referenced for certain functions,
  * such as logging, but may fail depending on where the fatal error is located (thus creating
  * a double fatal error) and so should not be relied upon - this is a best-effort feature.
  *
  * @filter pf4wp_error_contactmsg_[short plugin name]
  * @internal
  * @since 1.1
  */
 public final function _onShutdown()
 {
     $error = error_get_last();
     $pf4wp_instance = null;
     // Check if we have an error
     if (!is_array($error) || !array_key_exists('file', $error)) {
         return;
     }
     // Obtain the true plugin base, if possible. Note: plugin_basename() already normalizes slashes
     list($plugin_base_dir) = explode('/', plugin_basename($error['file']));
     // Return if the error wasn't generated by a plugin
     if (empty($plugin_base_dir)) {
         return;
     }
     // Determine if the error was generated by a PF4WP instance
     foreach (self::$instances as $instance_class => $instance) {
         list($instance_base_dir) = explode('/', $instance->getPluginBaseName());
         if (strcasecmp($instance_base_dir, $plugin_base_dir) === 0) {
             $pf4wp_instance = $instance;
             break;
         }
     }
     // The plugin isn't a PF4WP instance, nothing for us to do
     if (!isset($pf4wp_instance)) {
         return;
     }
     $error_type = '';
     // Handle error(s)
     switch ($error['type']) {
         case E_ERROR:
             $error_type = empty($error_type) ? 'E_ERROR' : $error_type;
             // no break - Irrecoverable, fatal error
         // no break - Irrecoverable, fatal error
         case E_USER_ERROR:
             $error_type = empty($error_type) ? 'E_USER_ERROR' : $error_type;
             // no break - Irrecoverable, fatal error (user defined)
         // no break - Irrecoverable, fatal error (user defined)
         case E_CORE_ERROR:
             $error_type = empty($error_type) ? 'E_CORE_ERROR' : $error_type;
             // no break - Irrecoverable, fatal core error (PHP)
         // no break - Irrecoverable, fatal core error (PHP)
         case E_COMPILE_ERROR:
             $error_type = empty($error_type) ? 'E_COMPILE_ERROR' : $error_type;
             // no break - Irrecoverable, fatal compile-time error (Zend)
         // no break - Irrecoverable, fatal compile-time error (Zend)
         case E_RECOVERABLE_ERROR:
             $error_type = empty($error_type) ? 'E_RECOVERABLE_ERROR' : $error_type;
             // no break - Recoverable, considered fatal for now
             $deactivated = false;
             $deactivated_msg = '';
             $error_logged_msg = '';
             // Try logging the error to a file
             $error_logged = $pf4wp_instance->log(sprintf('%s "%s" %d "%s"', $error_type, $error['file'], $error['line'], addslashes($error['message'])), self::LOG_ERROR) === 1;
             if ($error_logged) {
                 $error_logged_msg = sprintf(__('<p>A log of the error can be found in the file <code>%s</code></p>', $pf4wp_instance->getName()), $pf4wp_instance->getLogFile());
             }
             // If not in WP Debug mode, de-activate the plugin if possible
             if (!defined('WP_DEBUG') || defined('WP_DEBUG') && WP_DEBUG === false) {
                 if (!function_exists('deactivate_plugins')) {
                     @(include_once ABSPATH . 'wp-admin/includes/plugin.php');
                 }
                 if (function_exists('deactivate_plugins')) {
                     deactivate_plugins($pf4wp_instance->getPluginBaseName(), true);
                     $deactivated = true;
                     $deactivated_msg = __('<p>Because of this error, the plugin was automatically deactivated to prevent it from causing further problems with your WordPress site.</p>', $pf4wp_instance->getName());
                 }
             }
             // Display a full-fledged error in Admin
             if (is_admin()) {
                 // Allow the plugin to define a message on how to be contacted
                 $contact_msg = apply_filters('pf4wp_error_contactmsg_' . $pf4wp_instance->getName(), sprintf(__('<p>Please contact the plugin author <a href="%s" target="_blank">%s</a> with the above details%s if this problem persists.</p>', $pf4wp_instance->getName()), PluginInfo::getInfo(false, $pf4wp_instance->getPluginBaseName(), 'AuthorURI'), PluginInfo::getInfo(false, $pf4wp_instance->getPluginBaseName(), 'Author'), $error_logged ? ' or the logfile' : ''), $error_type, $error, $error_logged);
                 wp_die(sprintf(__('<h1>Fatal Error (%s)</h1>' . '<p><strong>There was a fatal error in the plugin %s.</strong></p>' . '<p>The error occurred in file <code>%s</code> on line %d. The cause of the error was:</p>' . '<p><pre>%1$s: %s</pre></p>' . '%s' . '%s' . '%s', $pf4wp_instance->getName()), $error_type, $pf4wp_instance->getDisplayName(), $error['file'], $error['line'], $error['message'], $deactivated_msg, $error_logged_msg, $contact_msg), sprintf(__('Fatal Error (%s)', $pf4wp_instance->getName()), $error_type), array('back_link' => true));
             } else {
                 /* If the plugin was deactivated, reload the page so the user does not stare at a
                  * blank page. We can't do this using headers, as they have already been sent.
                  */
                 if ($deactivated) {
                     printf("<head><script type=\"text/javascript\">/* <![CDATA[ */window.location.reload(true);/* ]]> */</script></head>\n" . "<body><noscript>" . __("Please <a href=\"%s\">click here</a> to reload this page.", $pf4wp_instance->getName()) . "</noscript></body>", $_SERVER['REQUEST_URI']);
                 }
                 return;
             }
             break;
             // Any other errors are ignored
     }
 }
Example #4
0
 /**
  * Settings Menu
  */
 public function onSettingsMenu($data, $per_page)
 {
     //global $wp_version, $wpdb;
     // Generate a list of galleries, including a default of "None", and set a flag if we can use collages
     $galleries = array_merge(array(array('id' => 0, 'name' => __('-- None (deactivated) --', $this->owner->getName()), 'selected' => $this->owner->options->active_gallery == false)), $this->owner->getSettingGalleries($this->owner->options->active_gallery));
     // Grab the overlays and add a default of "None"
     $overlays = array_merge(array(array('value' => '', 'desc' => __('-- None (deactivated) --', $this->owner->getName()), 'selected' => $this->owner->options->active_overlay == false)), $this->owner->getSettingOverlays($this->owner->options->active_overlay));
     // Grab Custom Post Types
     $custom_post_types = array();
     $display_custom_post_types = $this->owner->options->display_custom_post_types;
     foreach (get_post_types(array('_builtin' => false, 'public' => true), 'objects') as $post_type_key => $post_type) {
         if ($post_type_key !== Main::PT_GALLERY) {
             $custom_post_types[$post_type_key] = array('name' => $post_type->labels->name, 'display' => isset($display_custom_post_types[$post_type_key]) ? $display_custom_post_types[$post_type_key] : true);
         }
     }
     // Template exports:
     $vars = array('nonce' => wp_nonce_field('onSettingsMenu', '_nonce', true, false), 'submit_button' => get_submit_button(), 'galleries' => $galleries, 'overlays' => $overlays, 'background_color' => get_background_color(), 'custom_post_types' => $custom_post_types, 'bg_positions' => $this->owner->getBgOptions('position', true), 'bg_repeats' => $this->owner->getBgOptions('repeat', true), 'bg_transitions' => $this->owner->getBgOptions('transition', true), 'corner_locations' => $this->owner->getBgOptions('corner', true), 'roles' => $this->owner->getBgOptions('role', true), 'plugin_base_url' => $this->owner->getPluginUrl(), 'debug_info' => $this->owner->getDebugInfo(), 'plugin_name' => $this->owner->getDisplayName(), 'plugin_version' => $this->owner->getVersion(), 'plugin_home' => \Pf4wp\Info\PluginInfo::getInfo(false, $this->owner->getPluginBaseName(), 'PluginURI'));
     // Merge template exports with values of options
     $vars = array_merge($vars, $this->getSettingOptions(true));
     $this->owner->template->display('settings.html.twig', $vars);
 }