Can't trigger theme update from a third-party source via Updates API in WordPress - wordpress

I'm trying to update my theme via Updates API in WordPress and can't get it to work.
Here's the transient value:
(object) array(
'last_checked' => 1675756430,
'checked' => array(
'chipmunk-lite' => '1.0',
'chipmunk-theme' => '1.17.1',
),
'response' => array(
'chipmunk-theme' => array(
'theme' => 'chipmunk-theme',
'new_version' => '1.18.0',
'url' => 'https://chipmunktheme.com',
'package' => 'https://app.lemonsqueezy.com/download/unique_id',
'requires' => NULL,
'requires_php' => NULL,
'sections' => array(
'description' => '<p>Makes it ridiculously easy to make a content curation website for marketing, authority or just for fun. No coding skills required.</p>',
'changelog' => '1.18.0',
),
),
),
'no_update' => array(),
'translations' => array(),
)
The update alert does not show up. Is there anything wrong with it?
I'm following this guide: https://make.wordpress.org/core/2020/07/30/recommended-usage-of-the-updates-api-to-support-the-auto-updates-ui-for-plugins-and-themes-in-wordpress-5-5/

Related

Getting values from Kirki customizer fields in WordPress Theme

I'm using the Kirki plugin to add fields and sections in the WordPress customizer. So far, I can get a field to be added to the customizer, but I'm confused on how to return that data back into my theme. I'm kinda tired so I might be missing something. This is what I have so far:
Kirki::add_config('theme_config_id', array(
'capability' => 'edit_theme_options',
'option_type' => 'theme_mod',
));
Kirki::add_section('footer_section', array(
'title' => __('Footer'),
'description' => __('Add custom footer here'),
'panel' => '', // Not typically needed.
'priority' => 160,
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
));
Kirki::add_field('theme_config_id', [
'type' => 'editor',
'settings' => 'my_setting',
'label' => esc_html__('Footer Content', 'kirki'),
'description' => esc_html__('This content will show in the footer.', 'kirki'),
'section' => 'footer_section',
'default' => '',
]);
I was reading on trying to the values out from here using this:
$value = Kirki::get_option( $config_id, $option_id );
But I'm not sure where (or what) the $config_id or $option_id would be?
I have a feeling that I'm missing something and I've read through the docs and I feel that I'm not getting it.
This is the correct code
$value = Kirki::get_option( 'config_id', 'option_id' );
so in your case,
$value = Kirki::get_option( 'theme_custom', 'footer_content' );
After digging through the internet a little bit, I was able to read through some more documentation as well as some other examples and I was able to figure out what I was doing wrong. Overall, I was close, but I ended up cleaning it up and just using the WordPress get_theme_mod() outright in my template file (in this case it was the footer.php file).
Here's what I ended up with:
Kirki::add_config('theme_custom', array(
'capability' => 'edit_theme_options',
'option_type' => 'theme_mod'
));
Kirki::add_section('footer_section', array(
'title' => __('Footer'),
'description' => __('Add custom footer here'),
'panel' => '', // Not typically needed.
'priority' => 160,
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
));
Kirki::add_field('theme_custom', array(
'type' => 'editor',
'settings' => 'footer_content',
'label' => esc_html__('Footer Content', 'kirki'),
'description' => esc_html__('This content will show in the footer.', 'kirki'),
'section' => 'footer_section',
'default' => '',
'priority' => 10
));
and in my footer.php file, I added this:
<?php $value = get_theme_mod('footer_content', ''); ?>
<?php echo($value); ?>
Granted, this is a super basic way of implementing this. I'm going to try and figure out how to get it to refresh the customizer preview before you publish it. But for now, this seems to be working.

How to extend sorting order of Team Members

I'm using Business Lounge theme by RT themes with Elementor.
Wordpress version is current (5.2.1)
On the team page (Demo: https://businesslounge-demo.rtthemes.com/our-team/) there is a list of cards of team members. I want to change the order of the team members to an option that is not currently selectable.
The team member list is done with a shortcode [staff_box]
In Elementor edit mode I looks like this:
Edit:
The edit form is defined in
wp-content/plugins/businesslounge-extensions/inc/elementor-addons/staff.php
<?php
namespace Elementor;
// ...
class Widget_RT_Staff extends Widget_Base {
// ...
protected function _register_controls() {
// ...
$this->add_control(
'list_orderby',
[
'label' => esc_html_x( 'List Order By', 'Admin Panel','businesslounge' ),
'description' => esc_html_x('Sorts the posts by this parameter', 'Admin Panel','businesslounge' ),
'type' => Controls_Manager::SELECT,
'default' => "date",
"options" => array(
'date' => esc_html_x('Date',"Admin Panel","businesslounge"),
'author' => esc_html_x('Author',"Admin Panel","businesslounge"),
'title' => esc_html_x('Title',"Admin Panel","businesslounge"),
'modified' => esc_html_x('Modified',"Admin Panel","businesslounge"),
'ID' => esc_html_x('ID',"Admin Panel","businesslounge"),
'rand' => esc_html_x('Randomized',"Admin Panel","businesslounge"),
)
]
);
// ...
}
// ...
}
Plugin::instance()->widgets_manager->register_widget_type( new Widget_RT_Staff() );
The edit form is defined in `wp-content/plugins/businesslounge-extensions/inc/editor/staff_box.php`
like so
<?php
vc_map(
array(
'base' => 'staff_box',
'name' => _x( 'Team', 'Admin Panel','businesslounge' ),
'icon' => 'rt_theme rt_team',
'category' => array(_x( 'Content', 'Admin Panel','businesslounge' ), _x( 'Theme Addons', 'Admin Panel','businesslounge' )),
'description' => _x( 'Displays team members', 'Admin Panel','businesslounge' ),
'params' => array(
// ...
array(
'param_name' => 'list_orderby',
'heading' => _x( 'List Order By', 'Admin Panel','businesslounge' ),
"description" => _x("Sorts the posts by this parameter",'Admin Panel','businesslounge'),
'type' => 'dropdown',
"value" => array(
_x('Date','Admin Panel','businesslounge') => 'date',
_x('Author','Admin Panel','businesslounge') => 'author',
_x('Title','Admin Panel','businesslounge') => 'title',
_x('Modified','Admin Panel','businesslounge') => 'modified',
_x('ID','Admin Panel','businesslounge') => 'ID',
_x('Randomized','Admin Panel','businesslounge') => 'rand',
),
'save_always' => true
),
// ...
The output is defined in
wp-content/plugins/businesslounge-extensions/inc/shortcodes/staff_box.php
like so:
<?php
function rt_staff( $atts, $content = null ) {
// ...
//defaults
extract(shortcode_atts(array(
"id" => 'staff-'.rand(100000, 1000000),
"class" => "",
"list_layout" => "1/1",
"list_orderby" => "date",
"list_order" => "DESC",
"ids" => array(),
"box_style" => ""
), $atts));
// ...
//general query
$args=array(
'post_status' => 'publish',
'post_type' => 'staff',
'orderby' => $list_orderby,
'order' => $list_order,
'showposts' => 1000
);
// ...
$theQuery = query_posts($args);
// ...
What I want to do:
Add an option 'post_name' to the select box so that I can sort the team by a different field. I want to add
'Post name' => 'post_name',
How can I do this without changing the original source code?
I already have the child theme of business_lounge theme activated.
Do I need a custom extension for this?
You'd have to modify the original code.
You can't override the function unless the author applied a filter to the value returned, or used an action.
As gael notes in his answer, you can soften the blow of losing changes on updates by copying the original code into your child theme's functions.php then renaming the function - for e.g. to my_rt_staff() before adding in your modifications.
You would however still need to call the my_rt_staff() in the plugin instead of rt_stuff and you would have to make this change whenever the plugin was updated, but you wouldn't lose your code.
(Perhaps you could change the "list_orderby" => "date" in the default shortcode attributes to "list_orderby" => "post_name", as default in your modified my_rt_staff() method so it orders by name as default instead of date)
However, this does not help much in your specific circumstance, as the ideal modification you need to make is to the control itself, on the _register_controls() method in the Widget_RT_Staff class. You can override this by extending Widget_RT_Staff but you would still need to call your new class which results in you modifying the plugin code.
Without seeing how the Widget_RT_Staff class affects the shortocde, I can't be certain this would work, but based on the rt_staff() method, if you use the shortcode as [staff_box orderby="post_name"] you may get your intended result without having to touch any code.
You should be able to modify your plugin without losing update abilities by 'overriding' the function as described here:
https://stackoverflow.com/a/40856197/3623080
Make a copy of the function in your child-theme's functions.php, customize and rename it, use it in place of the original function.
Hope it will help

Visual Composer custom markup for custom shortcode (vc_map)

Trying to get custom_markup to work with the Visual Composer builder for WordPress.
Found Visual Composer change custom shortcode template and also Visual Composer custom shortcode template - custom_markup display user input but none of them has an answer.
Here's some documentation for the vc_map function https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524332
Here's my shortcode that I'm using, everything works perfectly, it just looks horrible in the backend ui
vc_map( array(
"name" => "example",
"base" => "adwise_vc_example",
"class" => "",
"category" => "Plugin name",
"icon" => "awm_vc_icon",
"custom_markup" => load_template( ADWISE_VC_DIR . '/vc_templates/adwise_example.php', false),
"params" => array();
Which currently looks like --> https://dl.dropboxusercontent.com/u/11204765/SS/mac/Screen%20Shot%202016-05-02%20at%2012.52.56.png
In the example below I've tried to set custom_markup to test
which results in https://dl.dropboxusercontent.com/u/11204765/SS/mac/Screen%20Shot%202016-05-02%20at%2012.45.55.png
vc_map( array(
"name" => "example",
"base" => "adwise_vc_example",
"class" => "",
"category" => "Plugin name",
"icon" => "awm_vc_icon",
"custom_markup" => "test",
"params" => array();
My primary/main problem is that I don't know how to get the values of each attribute for each shortcode to display in the template file.
I've looked almost everywhere for a solution, including browsing through other Visual Composer plugins to see how they've accomplished this.
Any help would be greatly appreciated!
What are you trying to accomplish exactly ? From the visual composer core code this is the custom markup for the tabs
'custom_markup' => '
<div class="wpb_tabs_holder wpb_holder vc_container_for_children">
<ul class="tabs_controls">
</ul>
%content%
</div>',
So maybe something like %customattr% will get your desired result?
just add an array with the shortcode attributes in 'params'
'params' => array(
array(
'type' => 'textfield',
'holder' => 'div',
'class' => '',
'heading' => __( 'Title' ),
'param_name' => 'title',
'value' => __( 'Titre' ),
'description' => __( 'Title' ),
),
array(
'type' => 'textarea',
'holder' => 'div',
'class' => '',
'heading' => __( 'Description' ),
'param_name' => 'desc',
'value' => __( 'description' ),
'description' => __( 'Description' ),
),
array(
'type' => 'attach_image',
'holder' => 'img',
'class' => '',
'heading' => __( 'Image' ),
'param_name' => 'img_url',
'value' => __( '' ),
'description' => __( 'Image' ),
),
)
and if you want hide a section in the backend just remove the 'holder' line

How to add custom fields for WordPress using Codeigniter RPC

I am using Codeignitor's RPC to post to a wordpress blog which is working fine BUT I cannot get the custom fields working. I assume the custom_fields is not correct "wrapped up" for the call?
$thePost = array(array('title' => array('Aston','string'),
'description' => array('this is the description','string'),
'wp_author_id' => array('2','int'),
'mt_keywords' => array('personal finance, money management','string'),
'mt_text_more' => array('read more','string'),
'categories' => array(array('Small Business'),'array'),
'custom_fields' => array(array('key' => 'image','value' => 'Say Hello'),'struct')),
'struct');
$thePost = array(array('title' => array('Aston','string'),
'description' => array('this is the description','string'),
'wp_author_id' => array('2','int'),
'mt_keywords' => array('personal finance, money management','string'),
'mt_text_more' => array('read more','string'),
'categories' => array(array('Small Business'),'array'),
'custom_fields' => array(
array(
array(
'key' => 'your key',
'value' => 'value'
),
'struct')
),'struct')),
'struct');
Take a look at this thread http://wordpress.org/support/topic/add-custom-fields-to-a-post-using-xml-rpc
Basically it says that you should be using metaWeblog.newPost instead of the wp api.

Correct way to use Drupal 7 Entities and Field API

I'm trying to use Drupal 7's entities and field API to correctly build a new module. What I have been unable to understand from the documentation is the correct way to use the new API to create a 'content type' (not a node type) with a number of set fields, such as Body.
I'm trying to set up the entity using hook_entity_info, then I believe I need to add the body field using field_create_instance, but I can't seem to get it to work.
In mycontenttype.module:
/**
* Implements hook_entity_info().
*/
function mycontenttype_entity_info() {
$return = array(
'mycontenttype' => array(
'label' => t('My Content Type'),
'controller class' => 'MyContentTypeEntityController',
'base table' => 'content_type',
'uri callback' => 'content_type_uri',
'entity keys' => array(
'id' => 'cid',
'label' => 'title',
),
'bundles' => array(
'mycontenttype' => array(
'label' => 'My Content Type',
'admin' => array(
'path' => 'admin/contenttype',
'access arguments' => array('administer contenttype'),
),
),
),
'fieldable' => true,
),
);
return $return;
}
/**
* Implements hook_field_extra_fields().
*/
function mycontenttype_field_extra_fields() {
$return['mycontenttype']['mycontenttype'] = array(
'form' => array(
'body' => array(
'label' => 'Body',
'description' => t('Body content'),
'weight' => 0,
),
),
);
return $return;
}
Then does this go in the .install file?
function mycontenttype_install() {
$field = array(
'field_name' => 'body',
'type' => 'text_with_summary',
'entity_types' => array('survey'),
'translatable' => TRUE,
);
field_create_field($field);
$instance = array(
'entity_type' => 'mycontenttype',
'field_name' => 'body',
'bundle' => 'mycontenttype',
'label' => 'Body',
'widget_type' => 'text_textarea_with_summary',
'settings' => array('display_summary' => TRUE),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'text_default',
),
'teaser' => array(
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
),
),
);
field_create_instance($instance);
}
I think your problem is that if node module is installed, there is already a field named 'body'. You should either re-name your field to something like 'mycontenttype_body' (comment.module uses comment_body), or re-use the 'body' field and skip the adding the field part and skip to adding the instance of it. The former is recommended over the latter.
Every field has an array property, entity_types, which limits the entities to which the field can be attached.
The best Drupal solution I can find, hook_field_create_field, can alter fields as they are created, but that's no good for the body field which is created on installation.
So my solution is just to edit the database directly in my hook_install
$data_col = db_query("SELECT data from field_config where field_name = 'body'")->fetchAssoc();
$data = unserialize($data_col['data']);
$data['entity_types'][] = 'MY_ENTITY_TYPE';
db_update('field_config')
->fields(array('data' => array('data' => serialize($data))))
->condition('field_name', 'body')
->execute();
just started down the same path here is a video from fago
Here's a nice repo to start: Lawmakers entity

Resources