简体   繁体   English

将jQuery插件转换为WordPress插件

[英]Converting a jQuery plugin into a WordPress plugin

For my WordPress site I really need to be able to have the functions that this library offers . 对于我的WordPress网站,我确实需要具有该库提供的功能。

My question is would it be possible to convert that jQuery plugin into a working WordPress plugin? 我的问题是,可以将jQuery插件转换为可工作的WordPress插件吗? And if so, how? 如果是这样,怎么办?

Would this be the correct way to make the init.php file? 这是制作init.php文件的正确方法吗?

<?php
/*
Plugin Name: jQuery Windows
Plugin URI: http://fstoke.me/jquery/window
Description: Sexy jQuery Windows. 
Version: 5.03 
Author: PC - Prashant Chaudhary
Author URI: http://fstoke.me/jquery/window
License: Creative Commons Attribution-ShareAlike 
*/
wp_enqueue_style(
    'jquerywindowstyles',
    WP_PLUGIN_URL.'/jQuery-windows/css/jquery.window.css',
    false,
    all);

// Add the scripts to the footer
function jquerywindowjs(){
    // Identify our javascript files
    wp_register_script(
        'jquery.window',
        WP_PLUGIN_URL.'/jquery-windows/jquery.window.js',
        array( 'jquery' ),
        "2.1.4",
        1 );
    wp_register_script(
        'jquery.window.min',
        WP_PLUGIN_URL.'/jquery-windows/jquery.window.min.js',
        array( 'jquery', 'jquery.window' ),
        "1.0",
        1 );
    // Then enqueue them
    wp_enqueue_script( 'jquery.window' );
}
// Action our scripts
add_action( 'wp_enqueue_scripts', 'jquerywindowjs' );
?>

The direct answer is Yes, It is possible . 直接答案是肯定的,这是可能的。 and easily. 轻松地 How to do that , is a different question and much more elaborated . 如何做到这一点,是一个不同的问题,而且要详尽得多。 But , if you need it for a one-time-use in one site - you always have the option to just include the script using wp_enqueue_script() , and the styles with wp_enqueue_style() in your functions.php and then use as is .. 但是,如果您需要在一个站点中一次性使用它-您始终可以选择仅使用wp_enqueue_script()包含脚本,并在您的functions.php包含wp_enqueue_style()样式,然后按原样使用。 。

But , you already have a lot of wordpress plugins that have similar functionality .. 但是,您已经有很多具有类似功能的wordpress插件..

see : http://wordpress.org/plugins/search.php?q=modal 参见: http : //wordpress.org/plugins/search.php?q=modal

or 要么

http://wordpress.org/plugins/search.php?q=popup http://wordpress.org/plugins/search.php?q=popup

It is not exluded that you can find the same script already as a plugin since there are literally hundreds of them.. 并不排除您可以找到与插件相同的脚本,因为实际上有数百个脚本。

Sure, all you do to make php/js code into a Wordpress plugin is give it the plugin header, set up a place where your code is inserted into wordpress (actions), and optionally create a configuration page for the plugin in PHP for the wordpress admin. 当然,要将php / js代码制作为Wordpress插件的全部工作就是给它提供插件标头,设置将代码插入到wordpress中的位置(动作),并可以选择在PHP中为该插件创建配置页面WordPress管理员

Basically, that would mean repackaging the current jquery plugin as a wordpress plugin. 基本上,这意味着将当前的jquery插件重新包装为wordpress插件。 It would function as a way to install this plugin into wordpress. 它将用作将此插件安装到wordpress中的一种方式。

WP has pretty good documentation: http://codex.wordpress.org/Writing_a_Plugin WP有相当不错的文档: http : //codex.wordpress.org/Writing_a_Plugin

I found that starting with a simple plugin (one php file), reading it, and seeing how it worked gave me enough info to start turning my code into WP plugins. 我发现从一个简单的插件(一个php文件)开始,阅读它,并查看它是如何工作的,这给了我足够的信息,可以开始将我的代码转换为WP插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM