Overwrite plugin files? - wordpress

I want to overwrite the file plugins/the-events-calendar/tickets/meta-box.php of the plugin The Events Calendar.
I followed the tutorial Overwrite Plugin Files but this is not working for me.
How can I overwrite this file?
i want to add new metabox in evetns Ticket section how can i do without edit the plugin file other wise overwrite that plugin files.

I don't have the paid Ticket plugin you refer to, but I took a bit of time to skim through the available GitHub code:
https://github.com/moderntribe/the-events-calendar/
It looks like the overwrite option (i.e. moving a file from the plugin folder to the tribe-events/ folder within your current theme directory) only applies to the views templates in:
https://github.com/moderntribe/the-events-calendar/tree/master/views
You can see for example the definition of the getTemplateHierarchy() function here.
But this overwrite option doesn't apply to the /admin-views/tickets/meta-box.php file, since it's included here with the default PHP include():
include $this->path . 'admin-views/tickets/meta-box.php';
through this method call here:
TribeEventsTicketsPro::instance()->do_meta_box( $post_id );
where the metabox comes from:
add_action( 'add_meta_boxes',
array( 'TribeEventsTicketsMetabox', 'maybe_add_meta_box' ) );
Looking at the source of this file, I found this part:
<?php do_action( 'tribe_events_tickets_metabox_advanced',
get_the_ID(), NULL ); ?>
This might be what you are looking for, if you want to add some extra tickets UI to the event editor. Try to hook into this tribe_events_tickets_metabox_advanced action to add your extra UI.
Hope this help.

Related

Triggering the Advanced Custom Fields (ACF) 'acf/save_post' Action

I've read the ACF 'acf/save_post' documentation here: acf-save_postDocs, which states this action enables one to add additional functionally before or after saving/updating a post. I want to test when this action is triggered.
I created a custom post type and a collection of ACF custom fields that are linked to this custom post type.This includes some ACF custom field types that I created using the ACF Starter Kit (see: creating-a-new-field-typeDocs), and they are used for some of the ACF custom fields. When I edit a custom post and then click the 'Update' button in the Gutenberg editor, I expect the 'acf/save_post' action to fire, but it does not seem to do so. Perhaps I am missing something. Here is the relevant code from my theme's 'function.php' file.
function my_acf_save_post($post_id) {
console_log("Testing...");
}
add_action('acf/save_post', 'my_acf_save_post', 20);
function console_log($output, $with_script_tags = true) {
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ')';
if($with_script_tags) {
$js_code = '<script>' . $js_code . '</script>';
}
echo $js_code;
}
Citation for the 'console_log' function: Kim Sia (see: https://stackify.com/how-to-log-to-console-in-php/).
I have my web browser's inspector window opened for my custom post type post's editor. After modifying the post and clicking 'Update', nothing displays in the inspector's console pane. I posted about this in the ACF forum but have received no response.
Your feedback is appreciated. Thank you.
Find below the instructions of how to debug that ACF hook in WordPress.
Official document for further details: https://wordpress.org/support/article/debugging-in-wordpress/
Note that there are other, more sophisticated and efficient ways of debugging in WordPress, for example using a proper debugger like xdebug.
These are usually harder to setup though, so here I am giving you the "WordPress in-built" way that might be simple, but is easy and effective.
ENABLE DEBUGGING
First, you need to enable debugging in wp-config.php, which I think you already did, but for others reading this answer, what you should do is:
Open in a text editor the file called wp-config.php, located in the wordpress installation root
Add the following to this file:
define('WP_DEBUG', true); => This enables debugging
define('WP_DEBUG_DISPLAY', false); => This prevents error logging from displaying on screen (affects both frontend and backend)
define('WP_DEBUG_LOG', true); => This logs the output to a file where you can then check it
You must add these yes or yes above the line
/* That's all, stop editing! Happy blogging. */
Done! Now you are logging, by default, to a file that will get generated in the root of the wp-content directory named debug.log.
WARNING! It is recommended to not leave debugging enabled on Production environments, as well as it is recommended to not leave the debug.log file as it could leave sensible site information exposed. Use for development only, and disable and remove file when finished. File can also be saved to a custom file name and location, see docs.
ERROR LOG
console.log is usually used for debugging js.
To log your function in PHP using the enabled debugger above, do the following:
function my_acf_save_post($post_id) {
error_log( 'Saved post ID : ' . $post_id, false);
error_log( var_export($_POST, true), false );
//If you want to log what got saved to the database
error_log( var_export(get_post($post_id), true), false );
}
add_action('acf/save_post', 'my_acf_save_post', 20);
You should find the saved post data and the ACF data recorded in a file named debug.log in your wp-content directory root.
LOGGING TO SCREEN
If instead what you want is to see the output that would have got written to the file, but directly on the screen, you don't need error_log() function, and instead you do that as shown below:
function my_acf_save_post($post_id) {
echo 'Saved post ID : ' . $post_id;
// Add <pre> tags to format the output in an easily readable way:
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
add_action('acf/save_post', 'my_acf_save_post', 20);

Translate plugin and wordpress and the same time

I have seen many questions and answers but none that fit the bill. So here is my issue.
I have a plugin that I have localized which works fine on it's own when you add
define('WPLANG', 'my-plugin-name-de_DE');
to the wp-config file. But then when someone try's to translate the rest of the wp site it will not show the languange.
What am I missing here? I even tried naming the files I added the the wp-content folder to be the same name as my plugin... for example my-plugin-name-de_DE.po and .mo and no luck.
ANSWER
Ok so in wordpress 4.0 you can now select your language from the settings /general page.
My plugin was localized using the code
function plugin_action_init()
{
// Localization
load_plugin_textdomain('my-plugin-name', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
// Add actions
add_action('init', 'plugin_action_init');
Example of a string that would get translated.
_e('Simple text example', 'my-plugin-name');
SO all that needed to be done to get my plugin's and wordpress's translation to work at the same time was to upload the wp language that I want to the wp-content/languages folder. Making sure the file name was simply de_DE.mo and de_DE.po
Such a simple mistake :)

Changes on archive-product.php doesn't work

I'm trying to customize the standard woocommerce theme and so far that has worked well. I copied all template files from /plugins/woocommerce/templates to /mytheme/woocommerce and customized the files.
But when i'm change something in archive-product.php nothing happens? I even tried to customize this in the core files (/plugins/woocommerce/templates/archive-product.php) but i doesn't work.
I want to change the class of the h1 heading: <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>.
So i looked up all woocommerce template files, the class page-title occurs only in this one file (to prevent editing the wrong file).
Edit:
In detail, i want to customize the theme used in this path: http://example.com/product-category/mycategory
I tried all the above solutions, to no avail. No matter what I did, the archive-product.php was not being used at all. Instead, most woocommerce pages were using page.php from my theme.
The solution for me was to add theme support... Which, it's been a while since I used woocommerce, so I completely forgot about that. But after adding the following line to my functions.php file, archive-product.php is now being used (/mytheme/woocommerce/archive-product.php) and I can update it, as I should be able to.
add_theme_support('woocommerce');
Seems this is STILL an issue in Woocommerce. For anyone landing here, the following solution was working for me as of version 2.1.6.
Apparently the problem is due to the function woocommerce_content() outputting the wrong page for archive content.
I used the following to get around it:
replace woocommerce_content() in woocommerce.php with:
if ( is_singular( 'product' ) ) {
woocommerce_content();
}else{
//For ANY product archive.
//Product taxonomy, product search or /shop landing
woocommerce_get_template( 'archive-product.php' );
}
Credit: found the solution here
Here's how I fixed mine:
Delete woocommerce.php in your theme folder.
Copy TEMPLATE folder in woocommerce plugin dir, paste it in your THEME folder, and rename it to woocommerce.
Open the folder you just renamed, go to shop folder, and edit wrapper-start.php and wrapper-end.php.
If you use the woocommerce.php method you cannot customize archive-product. You must use the hooks method
http://docs.woothemes.com/document/third-party-custom-theme-compatibility/
Please note: when creating woocommerce.php in your theme’s folder, you won’t be able to override the woocommerce/archive-product.php custom template as woocommerce.php has the priority over archive-product.php. This is intended to prevent display issues.
For others searching here, doublecheck the path. It is for example not /mytheme/woocommerce/templates/archive-product.php but only /mytheme/woocommerce/archive-product.php. I didn't have to apply #Talk nerdy to me's patch or any other to make it work.
you need to edit the file "taxonomy-product_cat.php" and add a conditional is_product_category( 'mycategory' ).
open your theme folder and add a new subfolder named "woocommerce" to it.
copy the files "archive-product.php" and "taxonomy-product_cat.php" from /plugins/woocommerce/templates to the woocommerce subfolder in your theme.
rename "archive-product.php" to "archive-mycategory.php" (or whatever you like, this will be the template file to the category).
open "taxonomy-product_cat.php" and wrap the wc_get_template( 'archive-product.php' ); with:
if (is_product_category( 'mycategory' )){
wc_get_template( 'archive-mycategory.php' );
} else {
wc_get_template( 'archive-product.php' );
}

Extend existing wordpress plugin

I was wondering if I could extend a existing wordpress plugin. For example adding some new features but without touching the original plugin files. Is this possible?
EDIT
I found the solution. For example in woocommerce plugin, I need to add some html to the sigle product so I wrote in function.php:
add_action( 'woocommerce_single_product_summary', 'woocommerce_single_product_my_custom_function', 15 );
function woocommerce_single_product_my_custom_function(){
echo '<p>this is my html code</p>';
}
unless the original defines hooks to extend, I am afraid this will not be possible. I suggest the way you would do that is copy the plugin directory and give it a different name in its definition

WordPress Plugin Localization

I've just built my first plugin for WordPress, and even if it's not a great "code poetry" it works as it should. It's a plugin that transform the default wp gallery using the GalleryView 3.0 jQuery plugin (http://spaceforaname.com/galleryview).
The only thing I'm not able to do is localization.
Localization for this plugin in means translating the admin interface, where someone can configure the jQuery plugin options to change the aspect of the resulting gallery.
I've tried to follow the millions of tutorials present on the web, read a lot of posts about this issue on forums and followed the guidelinees of codex... but still with no luck.
this is what I've done:
every text line is inside a gettext function ( __ and _e )
using poedit I created the .po and .mo file scanning the plugin directory (everything went ok), then i added translations on that file.
I named the .po file like that NAME-OF-THE-PLUGIN-it_IT.po (the .mo file was generated with the same name)
I've put the translations files inside the plugin folder/languages (name of the folder is the same of the plugin and of the translations files)
then I've tried to add the load_plugin_textdomain function inside the main plugin file. I've tried because there's no way to get it working.
The only thing on which I'm not sure is the fact that the plugin I've created is not under a class+constructor functions... just because I'm still not so good in coding.
But I've put the load_plugin_textdomain inside an init add_action, like this:
add_action('init', 'gw_load_translation_file');
function gw_load_translation_file() {
// relative path to WP_PLUGIN_DIR where the translation files will sit:
$plugin_path = dirname(plugin_basename( __FILE__ ) .'/languages' );
load_plugin_textdomain( 'gallery-view-for-wordpress', false, $plugin_path );
}
the lines above are not inside a logic, they are just in the main plugin file, like that.
this is an example of my use of gettext functions:
<h3><?php _e('Panel Options','gallery-view-for-wordpress') ?></h3>
What did I not understand?
My mistake was on language files path declaration.
this fixed:
$plugin_path = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
this was wrong:
$plugin_path = dirname(plugin_basename( __FILE__ ) .'/languages' );
I was answered on Wordpress Stack Exchange
Contrary to my previous statement, I've succeeded using this filename: gallery-view-for-wp-it_IT.mo
Strange, though - themes use just it_IT.mo.

Resources