WPLib::trigger_error PHP Method

trigger_error() static public method

Triggers error message unless doing AJAX, XMLRPC or Cron; then it logs the error but only if Development mode.
static public trigger_error ( string $error_msg, integer $error_type = E_USER_NOTICE, boolean $echo = false )
$error_msg string
$error_type integer
$echo boolean If true use 'echo', if false use trigger_error().
    static function trigger_error($error_msg, $error_type = E_USER_NOTICE, $echo = false)
    {
        $is_development = static::is_development();
        if (!static::doing_ajax() && !static::doing_xmlrpc() && !static::doing_cron()) {
            if ($is_development) {
                if ($echo) {
                    echo "{$error_msg} [{$error_type}] ";
                } else {
                    trigger_error($error_msg, $error_type);
                }
            }
        } else {
            if ($is_development || static::do_log_errors()) {
                /**
                 * ONLY triggers errors:
                 *      IF runmode() == WPLib::DEVELOPMENT
                 *      OR define( 'WPLIB_LOG_ERRORS', true ) in /wp-config.php.
                 *
                 * For runmode() == WPLib::DEVELOPMENT define( 'WPLIB_RUNMODE', 0 ) in /wp-config.php.
                 */
                error_log("{$error_msg} [{$error_type}]");
            }
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Register the post type inside of an Item classes' on_load() method.
  *
  * @param array $args
  *
  * @link  http://codex.wordpress.org/Function_Reference/register_post_type#Parameters
  */
 static function register_post_type($args = array())
 {
     $args = wp_parse_args($args, array('label' => WPLib_Posts::_get_post_type_label(static::POST_TYPE, 'name'), 'labels' => WPLib_Posts::_get_post_type_labels(static::POST_TYPE)));
     if (isset($args['taxonomies'])) {
         $message = 'Cannot set taxonomies via WPLib::%s(). Assign this post type via WPLib::register_taxonomy()';
         WPLib::trigger_error(sprintf($message, __METHOD__));
     }
     WPLib_Posts::_set_post_type_args(static::POST_TYPE, $args);
 }
All Usage Examples Of WPLib::trigger_error