调试插件安装?

问题描述 投票:0回答:1

我正在开发一个插件,在最近的更改之前一切都很顺利。不幸的是,由于硬件问题,之前的版本已经丢失。是的,我在开发项目时确实经常进行备份。 :-(

我正在尝试找出如何找到 WP 在尝试安装插件时遇到的错误。我已打开调试,并且可以看到日志文件。但我在安装尝试中没有看到任何错误/警告。

有没有一种工具或方法可以检查插件以识别插件中缺少的内容,从而显示我应该查看的位置?

更新后,当我尝试从上传插件管理页面安装插件时,出现以下错误:

Unpacking the package…

Installing the plugin…

The package could not be installed. No valid plugins were found.

Plugin installation failed.

编辑:

如果没有看到您的文件,就无法进行调试。插件的基本文件中有什么,例如索引.php?而且一切都很顺利,直到最近的变化,这意味着什么?你改变了什么?

文件名是

csttoc_makeindex.php
,slug 名称是
csttoc_makeindex

我并不是在实际调试方面寻求帮助。我正在询问有关如何查看安装功能遇到的错误的信息。

由于硬件故障,更改丢失了,而且有好几个。我拥有的唯一副本是编辑器(VScode)和服务器上的内容。我用于备份的电脑断电后,我的备份丢失了。我唯一拥有的备份是在开发初期,而且非常不完整。

代码:

<?php
/*
    Contributors: sloanthrasher
    Tags: table of contents, toc, index, page index, headings  
    Requires at least: 5.0  
    Tested up to: 6.6
    Requires PHP: 7.2  
    Stable tag: 1.0  
    Donate link: https://sloansweb.com/say-thanks/
    Author: Sloan Thrasher
    Author URI: https://sloansweb.com/page-4/
    License: GPLv3 or later
    License URI: http://www.gnu.org/licenses/gpl-3.0.html

    A plugin to generate a dynamic, hierarchical table of contents (TOC) based on page headings using a customizable shortcode.
*/

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

// Enqueue JavaScript and CSS


/**
 * Enqueues the csttoc-idx-script JavaScript file for use in the plugin.
 *
 * @return void
 */
function csttoc_enqueue_scripts()
{
    $ver = '1.0';

    wp_enqueue_script('csttoc-idx-script', plugins_url('js/csttoc-idx-script.js', __FILE__), array('jquery'), $ver, true);
}
add_action('wp_enqueue_scripts', 'csttoc_enqueue_scripts');

/**
 * Enqueues the selected style and plugin's stylesheet.
 *
 * @return void
 */
function csttoc_enqueue_assets()
{
    csttoc_enqueue_scripts();
    // Enqueue the selected style
    $options = get_option('csttoc_options');

    // Enqueue the plugin's stylesheet.
    $style = isset($options['style']) ? $options['style'] : 'css/csttoc_on_right.css';

    if ($style !== 'custom') {
        wp_enqueue_style('csttoc-style', plugins_url($style, __FILE__), array(), $ver);
    } else {
        if (isset($options['custom_css'])) {
            wp_add_inline_style('csttoc-style', $options['custom_css']);
        }
    }
}


/**
 * Generates a shortcode for displaying an index of headings on a page.
 *
 * @param array $atts An array of shortcode attributes.
 *                    - title: The title of the index (default: 'In This Article').
 *                    - selectors: The CSS selectors for the headings to include in the index (default: 'h2, h3, h4').
 * @return string The HTML for the index shortcode.
 */
function csttoc_index_shortcode($atts = [])
{
    csttoc_enqueue_assets();
    $options = get_option('csttoc_options');
    $default_selectors = isset($options['default_selectors']) ? $options['default_selectors'] : 'h2, h3, h4';
    $title = isset($atts['title']) && !empty($atts['title']) ? $atts['title'] : esc_html_e('In This Article');
    $selectors = isset($atts['selectors']) && !empty($atts['selectors']) ? $atts['selectors'] : $default_selectors;

    // Enqueue the selected style
    $options = get_option('csttoc_options');

    // Enqueue the plugin's stylesheet.
    $style = isset($options['style']) ? $options['style'] : 'css/csttoc_on_right.css';

    if ($style !== 'custom') {
        wp_enqueue_style('csttoc-style', plugins_url($style, __FILE__), array(), $ver);
    } else {
        if (isset($options['custom_css'])) {
            wp_add_inline_style('csttoc-style', $options['custom_css']);
        }
    }

    ob_start();
    ?>
    <div id="csttoc_pg_toc_list">
        <div class="csttoc-toc-heading"><i class="fa fa-spinner fa-spin" style="color:#f00;"></i></div>
        <div class="csttoc-toc-container"></div>
    </div>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            csttoc_generateIdx('<?php echo esc_js($selectors); ?>');
            jQuery('.csttoc-toc-heading').html('<?php echo esc_html($title); ?>');
        });
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('csttoc_index', 'csttoc_index_shortcode');


/**
 * Adds the 'Index For A Page' plugin settings page to the WordPress admin menu.
 *
 * @return void
 */
function csttoc_admin_menu()
{
    add_management_page(esc_html_e('Index For A Page', 'csttoc_index', 'csttoc-settings'), esc_html_e('Index For A Page', 'csttoc_index', 'csttoc-settings'), 'manage_options', 'csttoc-settings', 'csttoc_settings_page');
}
add_action('admin_menu', 'csttoc_admin_menu');

/**
 * Displays the settings page for the 'Index For A Page' plugin.
 *
 * @return void
 */
function csttoc_settings_page()
{
    ?>
    <div class="wrap">
        <h1><i><?php esc_html_e('Index For A Page', 'csttoc_index', 'csttoc-settings'); ?></i><?php echo esc_html_e(' Settings', 'csttoc_index', 'csttoc-settings'); ?>
        </h1>
        <form method="post" action="options.php">
            <?php
            settings_fields('csttoc_settings_group');
            do_settings_sections('csttoc-settings');
            submit_button();
            ?>
        </form>
    </div>
    <?php
}

/**
 * Initializes the settings for the CSTTOC plugin.
 *
 * Registers the setting group, section, and fields for the plugin's settings page.
 *
 * @return void
 */
function csttoc_settings_init()
{
    register_setting('csttoc_settings_group', 'csttoc_options');

    add_settings_section('csttoc_section', esc_html_e('Index A Page Settings', 'csttoc_index', 'csttoc-settings'));

    add_settings_field('title', esc_html_e('Page Index Title', 'csttoc_title_callback', 'csttoc-settings', 'csttoc_section'));
    add_settings_field('default_selectors', esc_html_e('CSS Selectors', 'csttoc_selectors_callback', 'csttoc-settings', 'csttoc_section'));
    add_settings_field('style', esc_html_e('Page Index Style', 'csttoc_style_callback', 'csttoc-settings', 'csttoc_section'));
    add_settings_field('custom_css', esc_html_e('Custom CSS', 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section'));
}
add_action('admin_init', 'csttoc_settings_init');

/**
 * Outputs a description of the section for the CSTTOC plugin settings page.
 *
 * @return void
 */
function csttoc_section_callback()
{
    echo '<p>' . esc_html_e("Customize the default settings for the Page Index.", 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section') . '</p>';
}

/**
 * Outputs a text input field for the Page Index title setting.
 *
 * Retrieves the current title value from the csttoc_options array and uses it to populate the input field.
 * If no title value is set, it defaults to 'Page Index'.
 *
 * @return void
 */
function csttoc_title_callback()
{
    $options = get_option('csttoc_options');
    $default_title = isset($options['title']) ? $options['title'] : esc_html_e('Page Index', 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section');
    echo "<input type='text' name='csttoc_options[title]' value='" . esc_attr($default_title) . "' class='regular-text'>";
}

/**
 * Outputs a text input field for the default CSS selectors setting.
 *
 * @return void
 */
function csttoc_selectors_callback()
{
    $options = get_option('csttoc_options');
    $default_selectors = isset($options['default_selectors']) ? $options['default_selectors'] : 'h2, h3, h4';
    echo "<input type='text' name='csttoc_options[default_selectors]' value='" . esc_attr($default_selectors) . "' class='regular-text'>";
}

/**
 * Outputs a select input field for the Page Index style setting.
 *
 * Retrieves the current style value from the csttoc_options array and uses it to populate the select field.
 * If no style value is set, it defaults to 'css/csttoc_on_right.css'.
 *
 * @return void
 */
function csttoc_style_callback()
{
    $options = get_option('csttoc_options');
    $style = isset($options['style']) ? $options['style'] : 'css/csttoc_on_right.css';
    ?>
    <select name="csttoc_options[style]" id="csttoc_style_select">
        <option value="css/csttoc_on_left.css" <?php selected($style, 'css/csttoc_on_left.css'); ?>>
            <?php echo esc_html_e('On Left', 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section'); ?>
        </option>
        <option value="css/csttoc_on_right.css" <?php selected($style, 'css/csttoc_on_right.css'); ?>>
            <?php echo esc_html_e('On Right', 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section'); ?>
        </option>
        <option value="custom" <?php selected($style, 'custom'); ?>>
            <?php echo esc_html_e('Custom', 'csttoc_custom_css_callback', 'csttoc-settings', 'csttoc_section'); ?>
        </option>
    </select>
    <?php
}

/**
 * Outputs a textarea field for custom CSS input and toggles its visibility based on the selected style.
 *
 * @return void
 */
function csttoc_custom_css_callback()
{
    $options = get_option('csttoc_options');
    $custom_css = isset($options['custom_css']) ? $options['custom_css'] : '';
    ?>
    <textarea name="csttoc_options[custom_css]" rows="10" cols="50"
        class="large-text code"><?php echo esc_textarea($custom_css); ?></textarea>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            function toggleCustomCss() {
                if ($('#csttoc_style_select').val() === 'custom') {
                    $('textarea[name="csttoc_options[custom_css]"]').closest('tr').show();
                } else {
                    $('textarea[name="csttoc_options[custom_css]"]').closest('tr').hide();
                }
            }
            toggleCustomCss();
            $('#csttoc_style_select').change(function () {
                toggleCustomCss();
            });
        });
    </script>
    <?php
}

任何我可以使用的工具的提示或指示将不胜感激!

wordpress debugging plugins
1个回答
0
投票

您的插件标头格式错误,您也忘记在标头中添加插件名称。这就是遇到错误的原因。

/*
 * Plugin Name:       My Basics Plugin
 * Plugin URI:        https://example.com/plugins/the-basics/
 * Description:       Handle the basics with this plugin.
 * Version:           1.10.3
 * Requires at least: 5.2
 * Requires PHP:      7.2
 * Author:            John Smith
 * Author URI:        https://author.example.com/
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Update URI:        https://example.com/my-plugin/
 * Text Domain:       my-basics-plugin
 * Domain Path:       /languages
 * Requires Plugins:  my-plugin, yet-another-plugin
 */

按照此格式作为您的插件标头

参考

© www.soinside.com 2019 - 2024. All rights reserved.