How to allow using shortcodes in post box - wordpress

I think this code is responsible for don't let me use shortcodes in Peepso post box.
public function peepso_activity_remove_shortcode( $content )
{
foreach($this->shortcodes as $shortcode=>$class) {
foreach($this->shortcodes as $shortcode=>$class) {
$from = array('['.$shortcode.']','['.$shortcode);
$to = array('['.$shortcode.']', '['.$shortcode);
$content = str_ireplace($from, $to, $content);
}
}
return $content;
}

Related

Wordpress - Exclude page from Sidebar widget?

I'm trying to hide a page from the 'Most Popular Post' widget in the sidebar.
I've got the 'WP Hide Post' plugin, It helps me hide from everywhere but that doesn't hide a page from the the widget.
Use the exclude argument in the WP_Query.
<?php
$excudeID = 30;// the post_id off the excluded page
$popularpost = new WP_Query( array( 'post__not_in' => array($excludeID) ) );
//use this query in your widget
while ( $popularpost->have_posts() ) : $popularpost->the_post();
the_title();
endwhile;
?>
Another option could be to write your own widget:
class drc_PopulairPostsWithoutThatone extends WP_Widget
{
public function __construct()
{
// Instantiate the parent object
parent::__construct(false, 'Populair Posts Title');
}
public function widget($args, $instance)
{
global $wpdb;
$excludeId = 30;
$return = "<ul>";
$query = $wpdb->prepare("SELECT * FROM wp_popularpostsdata, wp_posts WHERE wp_popularpostsdata.postid = $wpdb->posts.ID AND $wpdb->posts.post_type = 'page' AND wp_popularpostsdata.postid != %d ORDER BY pageviews DESC limit 10", $excludeId);
$tops = $wpdb->get_results($query);
foreach ($tops as $top) {
$return .= '<li>' . get_the_title($top->postid) . ' - ' . $top->pageviews . '</li>';
}
$return .= "</ul>";
return $return;
}
public function update($new_instance, $old_instance)
{
// Save widget options
}
public function form($instance)
{
// Output admin widget options form
}
}
function drc_register_widgets()
{
register_widget('drc_PopulairPostsWithoutThatone');
}
add_action('widgets_init', 'drc_register_widgets');
Query taken from: https://wordpress.org/support/topic/shortcode-get-the-least-popular-posts/
Documentation about widgets: https://codex.wordpress.org/Function_Reference/register_widget

show a message when updating a custom widget in wordpress backend

I'm developing a custom wordpress widget. The widget needs some data from the user and needs to check this data server-side.
I wrote the code that checks the data inside the function 'update' of the widget. When I press the button save of the widget the function update got called correctly and my validation is executed.
public function update( $new_instance, $old_instance ) {
$instance = array();
foreach ($this->fields as $field) {
$fieldName = $field['name'];
$instance[$fieldName] =
(!empty($new_instance[$fieldName]) strip_tags($new_instance[$fieldName]) : '' );
}
$check = validate($new_instance);
return $instance;
}
What I need is to display a message to the user based on the result of the validation. How can I do this? For what I've seen the function update is called through ajax so I can't use an admin notice.
Is it possible?How can I do that?
Try below code
add_action('admin_notices', 'misha_custom_order_status_notices');
function misha_custom_order_status_notices() {
global $pagenow, $typenow;
if( get_transient( 'fx-admin-notice-panel' )){
echo "<div class=\"updated\"><p>Custom notification comes here</p></div>";
}
}
public function update( $new_instance, $old_instance ) {
$instance = array();
foreach ($this->fields as $field) {
$fieldName = $field['name'];
$instance[$fieldName] =
(!empty($new_instance[$fieldName])?
strip_tags($new_instance[$fieldName]) :
''
);
}
$check = validate($new_instance);
set_transient( 'fx-admin-notice-panel', true, 5 );
return $instance;
}

unable to create drupal 7 module

Actually I am trying to create drupal module . But I am Faild
Here is my Code . I just want to display Iframe by using module .
CODE (MY_info.info):
name = MY_info
description = embedded widget
core = 7.x
CODE (My_info.module)
/**
* #file
* MY_info.module
*/
/**
* Implements hook_menu().
*/
function MY_info_menu() {
$items = array();
return $items;
}
/**
* Implements hook_form_alter().
*/
function MY_info_form_alter() {
}
Can Anyone hel me how to create it . ?
You Need To Create Block Module To Display Iframe
use hook_block_info() ; hook_block_view();
Try This One CODE (My_info.module)
<?php
function MY_info_block_info() {
$blocks['MY_info_block'] = array(
'info' => t('Your Content For Block Menu'),
// DRUPAL_CACHE_PER_ROLE will be assumed.
);
return $blocks;
}
function MY_info_block_view($delta = '') {
// This example is adapted from node.module.
$block = array();
switch ($delta) {
case 'MY_info_block':
$block['subject'] = t('Your Block Title');
$block['content'] = "Your Html Content";
break;
}
return $block;
}

save_post hook on curl responce error message display on Current post on like update message

On my plugin Return curl error message display on post page like as a
post update message.
public function __construct() {
add_action('init', array(&$this, 'init'));
add_action('admin_init', array(&$this, 'admin_init'));
add_action('admin_menu', array(&$this, 'add_page'));
add_action('admin_notices', array(&$this,'socipilot_admin_notice') );
add_action('admin_bar_menu', array(&$this, 'socipilot_adminbar_links' ), 1001 );
add_action('add_meta_boxes', array(&$this, 'add_meta_box' ) );
add_action('admin_enqueue_scripts', array(&$this,'socipilot_enqueue_scripts'));
add_action('save_post', array(&$this, 'save'));
add_filter('plugin_action_links_'.SOCI_PILOT_PLUGIN_BASENAME, array(&$this,'ts_add_plugin_action_links'));
// Listen for the activate event
register_activation_hook(SOCI_PILOT_FILE, array(&$this, 'activate'));
// Deactivation plugin
register_deactivation_hook(SOCI_PILOT_FILE, array(&$this, 'deactivate'));
}
public function save_socipost($post_id) {
$res = actionPosttest($options['public_key'],$options['private_key'],$data);
if($res->error==1){
global $my_error;
echo $post_error = $res->msg;
exit;
}
public function __construct() {
add_action('save_post', array(&$this, 'save_socipost'));
//add filter on construct
add_filter('post_updated_messages', array(&$this,'socipilot_updated_messages'));
}
public function socipilot_updated_messages($messages){
session_start();
//difine your message hear
$messages['post'][11] = sprintf( __($_SESSION['soci_error']));
return $messages;
}
public function save_socipost($post_id) {
global $post;
global $socipost_save_post_flag;
//function data
//my fix code for message hear
if($error_id==0 && isset($res)):
if ($socipost_save_post_flag == 0){
$res = actionPosttest($options['public_key'],$options['private_key'],$data);
}
$socipost_save_post_flag =1;
if($res->error==1){
global $my_error;
if($_SESSION['soci_error']){
session_destroy();
}else{
session_start();
$_SESSION['soci_error']= $res->msg;
}
wp_redirect(admin_url('post.php?post='.$post_id.'&action=edit&message=11'));
die();
}
//continew data
.
.
.
}

wordpress plugin shortcodes buffer

My developed wordpress plugin which is activated with a shortcode is breaking my admin area saying that header cannot be modified. Digging a bit deeper I got to know that if the function is getting echoed than I have this problem if I use return than is ok. But the problem with return is: that I use ajax to retrieve html and in this case no output is generated.
message Cannot modify header information - headers already sent by (output started at /var/www.... web/wordpress/wp-admin/admin-header.php
MyClass{
public function __construct()
public $data;
{
require_once(dirname(__FILE__) . '/class/class.another.php');
$this->data = new Another();
add_action( 'init', array( &$this, 'init' ) );
}
public function init()
{
add_shortcode( 'my_shortcode', array ($this, 'shortcode') );
if(isset($_POST['id'])){
$param = $this->data->output_ajax_html($_POST['id']);
echo $this->shortcode_html_extended($param);
//this part breaks the buffer without echo is working but the contertn won't show up
}
}
public function shortcode()
{
add_shortcode( 'my_shortcode', array ($this, 'shortcode_html') );
}
public function shortcode_html()
{
$html = "";
$html .="";
return $html;
}
public function shortcode_html_extended($param)
{
$html = "";
//mixed with php
$html .="";
return $html;
}
}
$test = new MyClass();

Resources