This section describes common problems when using the plugin and how to solve them.
If you haven't found your question, it is best to ask it in the official repository on
Github.
Recently Twitter banned the free use of its old API for new users.
Use API v2 provider if you got the error “You currently have Essential access which includes access to Twitter API v2 endpoints only.
If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal.” while sending a post to social network.
Read more in the setup guide.
Can I avoid storing social networks tokens in the database?
#
Yes, you can define a constant SOCIAL_PLANNER_PROVIDERS
with your settings.
The best place for this constant is in the file wp-config.php
or in the
functions.php
.
Define provider key as {network_name}-{index}
,
where index
is something alphanumeric and unique.
You can see correct network name and all availible network fields in
source
code.
Show me an example
define( 'SOCIAL_PLANNER_PROVIDERS', array(
'vk-1' => array(
'token' => 'token',
'group' => '-123',
),
'telegram-1' => array(
'token' => '123:token',
'group' => '123',
),
'facebook-1' => array(
'token' => 'token',
'group' => '123',
'title' => 'Facebook',
),
'twitter-1' => array(
'consumer_key' => 'key',
'consumer_secret' => 'secret',
'access_token' => 'token',
'access_secret' => 'secret'
)
) );
How can I show the settings page only to some users?
#
You can use filter social_planner_hide_settings
.
Show me an example
function my_hide_settings( $hide_settings ) {
$user = wp_get_current_user();
if ( empty( $user->user_login ) || 'admin' !== $user->user_login ) {
$hide_settings = true;
}
return $hide_settings;
}
add_filter( 'social_planner_hide_settings', 'my_hide_settings' );
Can I use html in the summary field when scheduling a new task?
#
You can use only Markdown **text here**
for bold and
__text here__
for italic to beatify Telegram announcements.
How to hide the metabox for custom post types?
#
Plugin shows metabox for all public post types except attachments.
You can override this behavior with the social_planner_post_types
filter.
Show me an example
function my_post_types( $post_types ) {
// Remove metabox from pages.
foreach ( $post_types as $i => $name ) {
if ( 'page' === $name ) {
unset( $post_types[ $i ] );
}
}
return $post_types;
}
add_filter( 'social_planner_post_types', 'my_post_types' );
What happens when you delete the plugin?
#
By default, when uninstalling the plugin through the admin panel, all database options are deleted,
including data on submitted tasks. If you want to keep them uninstall the plugin indirectly via the
filesystem.
Can I add a new provider?
#
Only 5 social networks are available for posting now.
Some more are likely to be added soon, but until that happens, you might want to write your own extension.
And it's not that hard to do.
You need to create a special social network class and connect it to the plugin.
There is an Example
of a non-existent network in below.
Copy it and replace the information in the methods.
Your class must provide NETWORK_NAME
constant and public static send_message
method.
You can see how the other classes of social networks of the plugin are implemented in the
repository.
Connect your class with a filter social_planner_networks
.
Example of the provider class
<?php
function add_example_network( $networks ) {
$networks['My_Network_Example'] = get_template_directory() . '/inc/class-network-example.php';
return $networks;
}
// This filter must execute before the `init` event.
add_filter( 'social_planner_networks', 'add_example_network' );
class My_Network_Example {
/**
* Unique network slug.
* Use latin alphanumeric characters and underscore only.
*/
const NETWORK_NAME = 'example';
/**
* Return human-readable network label
*/
public static function get_label() {
return 'Example';
}
/**
* Return network required settings fields
*/
public static function get_fields() {
$fields = array(
'token' => array(
'label' => 'Token',
'placeholder' => '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11',
'required' => true,
),
'group' => array(
'label' => 'Group ID',
'required' => true,
),
'title' => array(
'label' => 'Subtitle',
'hint' => 'Optional field.'
),
);
return $fields;
}
/**
* Send message method
*
* @param array $message Message data.
* @param array $settings Settings array from options.
*/
public static function send_message( $message, $settings ) {
// You should write this sending method using $message and $settings.
$response = self::my_sending_method( $message, $settings );
// If something went wrong you should return WP_Error.
if ( empty( $response ) ) {
return new WP_Error( 'sending', 'Example sending error' );
}
// If it is ok, you should return a message link or ID.
return 'https://example.com/' . $response;
}
That's all you need. Now check if the new provider has appeared on the Settings page.