Override Theme-Options.php file - php

I am having a difficult time removing the calling from my parents theme-options.php. My problem is this: My parent theme calls for the logo not from the header.php which I could easily replace but from the theme-options.php by placing the url path to the image like so require ( get_template_directory() . '/settings/theme-options.php' );
I want to "unrequire" this call in the child theme and add a function to call require ( get_stylesheet_directory() . '/theme-options.php' ); This way I can modify the options file and remove the call to the url. I have had a similar problem before and fixed it by using the unregister function but I am not sure on how to "unrequire" this call to the file.
Any help would be greatly appreciated.
After searching a little deeper there is a function that calls the default values like so :
function max_magazine_default_options() {
$options = array(
'logo_url' => get_template_directory_uri().'/images/logo.png',
'favicon_url' => '',
'rss_url' => '',
'show_slider' => 1,
'slider_category' => 0,
'show_carousel' => 1,
'carousel_category'=> 0,
'show_feat_cats' => 1,
'feat_cat1'=> 0,
'feat_cat2'=> 0,
'feat_cat3'=> 0,
'feat_cat4'=> 0,
'show_posts_list' => 1,
'show_author' => 1,
'show_page_comments' => 1,
'show_media_comments' => 1,
'ad468' => '<a href='.get_site_url().'><img src='.get_template_directory_uri().'/images/ad468.png /></a>',
'inline_css' => '',
'meta_desc' => '',
'stats_tracker' => '',
'google_verification' => '',
'bing_verification' => '',
);
return $options;
}
So im guessing I could remove this function and replace it with my own and alter the values?

The only way you would be able to do this without editing the parent is if they call require() within a function called by a hook such as init, setup_theme, etc. Then you could simply do:
remove_action( 'hook', 'their_function_name' );
And then you would have to copy/paste the function into your functions.php file, edit it, and then re-add it using the same hook:
add_action( 'hook', 'your_function_name' );
You may also have to make sure the priority (third argument) is correct on your function to make sure it properly overrides it.

Related

How to pass image references?

Context:
I am developing a custom Wordpress theme.
Objective:
On the home page, when you click, "stamps" are dotted about the window. I have the js functioning. Here's an example in which you can see exactly what I'm trying to do: https://omg-draft.superhi.com/
Problem:
I need a way to access the veggies in my main.js. I'm having trouble passing them from my functions.php to main.js. I have enqueued the js file and passed in the image files. In the console, I get back 'veggies is not defined'.
Here's the code from functions.php
add_action( 'admin_init', 'omedte_get_scripts' );
function omedte_get_scripts() {
wp_enqueue_script('main.js', get_template_directory_uri() . "/main.js", array(), null, true);
$veggies = array(
"beetroot" => get_theme_file_uri('/assets/beetroot.svg'),
"broccoli" => get_theme_file_uri('/assets/broccoli.svg'),
"capsicum" => get_theme_file_uri('/assets/capsicum.svg'),
"carrot" => get_theme_file_uri('/assets/carrot.svg'),
"corn" => get_theme_file_uri('/assets/corn.svg'),
"gourd" => get_theme_file_uri('/assets/gourd.svg'),
"kale" => get_theme_file_uri('/assets/kale.svg'),
"pumpkin" => get_theme_file_uri('/assets/pumpkin.svg'),
"spinach" => get_theme_file_uri('/assets/spinach.svg')
);
wp_localize_script( 'omedte_javascript_file', 'veggies', $veggies );
}
and here's my main.js:
let carrot = veggies.carrot;
let broccoli = veggies.broccoli;
let capsicum = veggies.capsicum;
let stamps = [
carrot,
broccoli,
capsicum
]
Might not be the only issue, but your handles don't match in your enqueue and localise statements.
Refer wp_localize_script()

Wordpress - How to read Post HTML output after 1 shortcode execution

I have custom WP plugin, which registers some shortcodes and run them in Post typically.
One Post typically has 2 or more of these shortcodes.
I need to find out if the first shortcode was executed and changed Post HTML somehow - so the second and next runs of shortcode don´t replace the HTML made by first shortcode run.
But I don´t know how.
I know, that it should be done by adding some parameter to shortcode like [shortcode first_run="true"], but it is the last acceptable solution, because it demands changing of previously generated shortcodes in Posts.
I know I can´t use get_the_content() - it shows the Post content from DB before shortcode runs.
I know I can´t use the_content() - cause it cycle the WP run
Thank you for help.
My sample of code (it doesn´t help too much I guess, but.. just to imagination):
function joreviewstable_func( $atts ) {
if (is_singular() || is_tag() ) {
$a = shortcode_atts( array(
'type' => "",
'id' => NULL,
'params' => NULL,
'limit' => NULL,
'tablesorter_disable' => NULL,
'disallow_images' => NULL,
'product_ids' => NULL,
'manufacturer' => NULL,
'manufacturer_serie' => NULL,
'no_sum' => NULL,
'custom_order' => NULL,
'vertical_design' => NULL
), $atts );
require_once( plugin_dir_path( __FILE__ ) . 'inc/shortcode.php');
$return = jo_reviews_shortcode_generate_table( $a['type'], $a['id'], $a['params'],
$a['limit'], $a['tablesorter_disable'], $a['disallow_images'],
$a['product_ids'], $a['manufacturer'], $a['manufacturer_serie'],
$a['no_sum'], $a['custom_order'], $a['vertical_design'] );
//$return = "<table><tr><td>data</td></tr></table>";
return $return;
} else {
return NULL;
}
add_shortcode( 'joreviewstable', 'joreviewstable_func' );
The jo_reviews_shortcode_generate_table function do some magic and returns html back to joreviewstable_func.
But I don´t know, how to get the edited Post HTML to strpos if it contains something.
You can do it by using global variables.
f.e.
function joreviewstable_func( $atts ) {
global $first_run;
if(!empty($first_run)) return;
$first_run=1;
//REST LINES HERE
}

WordPress theme behaving bad

Hope you all are doing great since last few days i am facing an issue with my WordPress site this is a plugin or theme i am not sure but the file is in theme which throws error of undefined function
because of this error i am not able to open my customize menu from wordpress admin panel
and once i commented the code line where this code exists it start working but widgets does not work properly like if i enable social icons in widgets i wont be able to disable them and save settings here is the code i have commented.
$jobcareer_opt_array = array(
'name' => esc_html__('Title', 'jobcareer'),
'desc' => '',
'hint_text' => '',
'echo' => true,
'field_params' => array(
'std' => esc_attr($jobcareer_widget_title),
/*'id' => cs_allow_special_char($this-
>get_field_id('title')),*/
'classes' => '',
/*'cust_id' => cs_allow_special_char($this-
>get_field_name('title')),*/
/*'cust_name' => cs_allow_special_char($this-
>get_field_name('title')),*/
'return' => true,
'required' => false
),
);
May be there is some version conflict between the theme and Codestar plugin. You can ask your theme's developer for that. Or as a temporary solution just remove cs_allow_special_char function and use its parameter insteaad. For example replace
cs_allow_special_char($this->get_field_name('title'))
with
$this->get_field_name('title')
and it should work then.
I checked the plugin's source, that function doesn't do any critical operation:
function cs_allow_special_char($input = ''){
$output = $input;
return $output;
}

Drupal 7 Messages only show after class registry clear

Need to show some messages from hook_block_view.
so in the function setting a message like:
drupal_set_message('Block should have loaded');
Does not work.
If I clear class registry, it works once, then every other time it does not show.
It looks like drupal is redirecting or something before the page is rendered. Using drupal_exit(); by the end of this function does show everything is correct so far, but does not make it to the final output.
Edit:
It works if I throw in drupal_flush_all_caches But then goes super slow obviously. Seems to be some sort of caching problem.
Turn off full caching for the block under hook_block_info() by setting 'cache' to: DRUPAL_NO_CACHE
function hook_block_info() {
$blocks = array();
$blocks['abc'] = array(
'info' => t('test block'),
'visibility' => 0,
'status' => TRUE,
'region' => 'none',
'weight' => 99,
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
Then try to write
drupal_set_message('Block should have loaded');
within hook_block_view and check now...
it may be help for you.

CakePHP extend currency formatting

I need to extend the number helper to include other currencies. Using the "addFormat" function in the number helper, I have created a new "CurrenciesHelper" to add these currencies.
<?php
class CurrenciesHelper extends NumberHelper {
I know I need to make it possible for this helper to run this function immediately. What am I missing to contain this so it runs and adds this format?
$this->Number->addFormat('CAD', array(
'before'=>'$',
'after' => false,
'zero' => 0,
'places' => 2,
'thousands' => '.',
'decimals' => ',',
'negative' => '()',
}
Starting CakePHP 2.1, you don't need to extend the helper to get this done. NumberHelper has been re-factored into CakeNumber class. If you go through the code, you can see that the formats are now stored as a static array.
That helps us configure currency formats within app/Config/core.php, like the following:
App::uses( 'CakeNumber', 'Utility' );
CakeNumber::addFormat(
'CAD',
array(
'before' => '$ ', 'after' => false,
'zero' => 0, 'places' => 2, 'thousands' => '.',
'decimals' => ',', 'negative' => '()', 'escape' => true
)
);
// ... and any more definitions to follow.
Once your currency definitions are part of the core configuration, you can use them in any view using NumberHelper like $this->Number->currency( $c, 'CAD' ).
PREVIOUS ANSWER CHANGED: Due to position of functions, after the fact. Had to change to:
function __beforeRender(){
}
Was causing overwriting of other custom currencies.
By encapsulating it in a construct
function, it run on helper
construction. I was sure to include
the parent constructor just in case.
function __construct() {
parent::__construct();
// code goes here
}

Categories