Firstly, I know this is 'bad' practice for several different reasons, but for reasons that I won't waste your time with it's something I need to do.
Using a fairly simple plugin and I've tried copying it into functions.php and updating the file paths and dependences, but I'm having some trouble.
Plugin file looks like this:-
$plugin_headers = get_file_data( __FILE__, array( 'Version' => 'Version', 'Name' => 'Plugin Name' ) );
/**
* We store our plugin data in the following global array.
* $my_unique_name with your unique name
*/
global $my_unique_name;
$my_unique_name = array();
$my_unique_name['version_key'] = strtolower( str_replace( ' ', '_', $plugin_headers['Name'] ) ) . '_version';
$my_unique_name['version_value'] = $plugin_headers['Version'];
/**
* When the user activates the plugin we add the version number to the
* options table as "my_plugin_name_version" only if this is a newer version.
*/
function inline_comments_acitvation(){
global $my_unique_name;
if ( get_option( $my_unique_name['version_key'] ) && get_option( $my_unique_name['version_key'] ) > $my_unique_name['version_value'] )
return;
update_option( $my_unique_name['version_key'], $my_unique_name['version_value'] );
}
register_activation_hook( __FILE__, 'inline_comments_acitvation' );
/**
* Delete our version number from the database when the plugin is activated.
*/
function inline_comments_deactivate(){
global $my_unique_name;
delete_option( $my_unique_name['version_key'] );
}
register_deactivation_hook( __FILE__, 'inline_comments_deactivate' );
if ( is_admin() )
require_once plugin_dir_path( __FILE__ ) . 'admin/admin-tags.php';
/**
* Theme only functions
*/
require_once plugin_dir_path( __FILE__ ) . 'inc/template-tags.php';
function inline_comments_enqueue_scripts(){
$plugin_headers = get_file_data( __FILE__, array( 'Version' => 'Version', 'Name' => 'Original Plugin Name' ) );
$clean_name = strtolower( str_replace( ' ', '-', $plugin_headers['Name'] ) );
wp_register_style( $clean_name . '-style', plugin_dir_url( __FILE__ ) . 'inc/css/style.css' );
wp_register_script( 'textarea_auto_expand-script', plugin_dir_url( __FILE__ ) . 'vendor/textarea-auto-expand/jquery.textarea_auto_expand.js' );
wp_register_script( $clean_name . '-script', plugin_dir_url( __FILE__ ) . 'inc/js/script.js', array('jquery', 'textarea_auto_expand-script') );
}
add_action('wp_enqueue_scripts', 'inline_comments_enqueue_scripts', 2);
After moving the plugin to the theme folder I've done the following: I've removed the pointless parts and in my functions.php I'm loading the main script.js (it loads) and the css, like so.
function inline_comments_enqueue_scripts(){
if ( is_singular() || is_page() ) {
wp_enqueue_style( 'inline-style', get_template_directory_uri() . '/css/inline-style.css', '10000', 'all' );
wp_enqueue_script( 'inline-script', get_template_directory_uri() . '/js/inline-script.js', array( 'jquery' ), MEDIUM_VERSION);
}
}
add_action('wp_enqueue_scripts', 'inline_comments_enqueue_scripts', 2);
Ok, so our script loads with our css.
The problem is the main part of the plugin that contains the templates, the functions and the ajax calls I can't get to load.
This part:- require_once plugin_dir_path( __FILE__ ) . 'inc/template-tags.php';
I've tried pasting this file into functions.php and nothing happens, it just doesn't work.
Probably making a really stupid mistake somewhere(other than building a plugin into a theme, heh).
inc
in your theme's directory, and inside it, add the filetemplate-tags.php
. The problem is that if I remember correctly,register_deactivation_hook
need the file to be inside theplugins
directory.template-tags.php
file, that doesn't seem to be used, but it could have the part where the AJAX action is registered, ad that is key if you are saying this plugin uses AJAX calls.