IT-Service-WordPress / WPF

Шаблон плагина для WordPress (CMS)
GNU General Public License v2.0
0 stars 0 forks source link

Генерировать ошибки в WPF #46

Open sergey-s-betke opened 10 years ago

sergey-s-betke commented 10 years ago

Там, где необходимо, генерировать ошибки следующим образом:

    $trace = debug_backtrace();
    trigger_error(
        'Undefined property via __get(): ' . $name .
        ' in ' . $trace[0]['file'] .
        ' on line ' . $trace[0]['line'],
        E_USER_NOTICE
    );
sergey-s-betke commented 10 years ago

Реализовал для этих целей функцию trigger_wpf_error. Она выполняет и действия trigger_error, и выдаёт admin notice, если включена опция WP_DEBUG.

sergey-s-betke commented 10 years ago

Всегда следует изучать ядро WordPress перед реализацией своего API. Переделал всё ещё раз на использование функции из ядра WordPress:

function _doing_it_wrong( $function, $message, $version ) {

    /**
     * Fires when the given function is being used incorrectly.
     *
     * @since 3.1.0
     *
     * @param string $function The function that was called.
     * @param string $message  A message explaining what has been done incorrectly.
     * @param string $version  The version of WordPress where the message was added.
     */
    do_action( 'doing_it_wrong_run', $function, $message, $version );

    /**
     * Filter whether to trigger an error for _doing_it_wrong() calls.
     *
     * @since 3.1.0
     *
     * @param bool $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true.
     */
    if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) {
        if ( function_exists( '__' ) ) {
            $version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version );
            $message .= ' ' . __( 'Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.' );
            trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
        } else {
            $version = is_null( $version ) ? '' : sprintf( '(This message was added in version %s.)', $version );
            $message .= ' Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.';
            trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
        }
    }
}

Её функционал, при необходимости, я могу расширить через 'doing_it_wrong_run' action.