Osclass forums
Support forums => Tips, tricks, and tutorials => Topic started by: AdrianOlmedo on March 29, 2015, 03:02:44 am
-
Can I copy the same class php Form.form.class.php to functions.php , changing the name of that php class?
I need to access the contents of the select html in my template css of <?php ItemForm::category_select(null, null, __('Select a category', 'realestate')); ?>
-
Hi,
Because of that function category_select doesn't use internal class syntax (something like $this->), you just can put a copy of the whole function in your theme functions.php, the only thing you need to do is change:
static public function category_select
to something such as:
function cust_category_select
Then you can adapt it to your needs, and replace in item-post.php and item-edit.php:
<?php ItemForm::category_select(null, null, __('Select a category', 'realestate')); ?>
to
<?php cust_category_select(null, null, __('Select a category', 'realestate')); ?>
Regards
-
Thanks for the clarification
-
Hi,
I also modified an existing core class but not by copying the whole class but by using the 'extends' functionality in which case there's no need to copy the whole class and you can simply add your own new function or a modified copy of a class function.
In your theme's functions.php you create it like this
class Your_Custom_Class extends ItemForm {
Your own custom (modified) class function
OR
Your base class edited function (an existing function of ItemForm using the same name here superseding the ItemForm original function.
}
Using this principle enables you to call ALL functions of class ItemForm including your own modified function by calling it using this code:
Your_Custom_Class::MyCustomFunction();
OR
Your_Custom_Class::ExistingFunctionName();
That's all.