patilswapnilv /
shortcodely
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /* |
||
| 3 | * Utilities for use all over shortcodely plugin |
||
| 4 | * Version 0.1 |
||
| 5 | * |
||
| 6 | * @package Shortcodely |
||
| 7 | */ |
||
| 8 | function shortcodely_show_shortcode_widget_possibilities() { |
||
| 9 | //function to show the widget possibilities |
||
| 10 | global $_wp_sidebars_widgets; |
||
| 11 | |||
| 12 | $sidebars_widgets = $_wp_sidebars_widgets; |
||
| 13 | ksort( $sidebars_widgets ); // push inactive down the bottom of the list |
||
| 14 | $text = '<ul>'; |
||
| 15 | foreach ( $sidebars_widgets as $sidebarid => $sidebar ) { |
||
| 16 | if ( is_array( $sidebar ) ) { |
||
| 17 | $text .= '<li><em>[do_widget_area ' . $sidebarid . ']</em><ul>'; |
||
| 18 | foreach ( $sidebar as $i => $w ) { |
||
| 19 | $text .= '<li>'; |
||
| 20 | $text .= '[do_widget id="' . $w . '"]'; |
||
| 21 | $text .= '</li>'; |
||
| 22 | } |
||
| 23 | $text .= '</ul></li>'; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | $text .= '</ul>'; |
||
| 27 | |||
| 28 | return $text; |
||
| 29 | } |
||
| 30 | |||
| 31 | /*-----------------------------------*/ |
||
| 32 | function shortcodely_get_widgets_sidebar( $wid ) { |
||
| 33 | /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. |
||
| 34 | take the first one that matches */ |
||
| 35 | global $_wp_sidebars_widgets; |
||
| 36 | |||
| 37 | foreach ( $_wp_sidebars_widgets as $sidebarid => $sidebar ) { |
||
| 38 | if ( is_array( $sidebar ) ) { // ignore the 'array version' sidebarid that isnt actually a sidebar |
||
| 39 | foreach ( $sidebar as $i => $w ) { |
||
| 40 | if ( $w == $wid ) { |
||
| 41 | return $sidebarid; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | return false; // widget id not in any sidebar |
||
| 48 | } |
||
| 49 | /*-----------------------------------*/ |
||
| 50 | function shortcodely_get_sidebar_id( $name ) { |
||
| 51 | /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. |
||
| 52 | take the first one that matches */ |
||
| 53 | global $wp_registered_sidebars; |
||
| 54 | |||
| 55 | foreach ( $wp_registered_sidebars as $i => $a ) { |
||
| 56 | if ( (isset( $a['name'] )) and ($a['name'] === $name) ) { |
||
| 57 | return $i; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | return false; |
||
| 62 | } |
||
| 63 | /*-----------------------------------*/ |
||
| 64 | function shortcodely_get_sidebar_name( $id ) { |
||
| 65 | /* dont need anymore ? or at least temporarily */ |
||
| 66 | /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */ |
||
| 67 | global $wp_registered_sidebars; |
||
| 68 | foreach ( $wp_registered_sidebars as $i => $a ) { |
||
| 69 | if ( (isset( $a['id'] )) and ($a['id'] === $id) ) { |
||
| 70 | if ( isset( $a['name'] ) ) { |
||
| 71 | return $a['name']; |
||
| 72 | } else { |
||
| 73 | return $id; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | return false; |
||
| 79 | } |
||
| 80 | /*-----------------------------------*/ |
||
| 81 | function shortcodely_check_if_widget_debug() { |
||
| 82 | global $said; |
||
| 83 | // only do these debug if we are logged in and are the administrator |
||
| 84 | |||
| 85 | if ( is_admin() ) { |
||
| 86 | return false; |
||
| 87 | } // if running in backend, then do not do debug. 20151217 |
||
| 88 | |||
| 89 | if ( ( ! is_user_logged_in()) or ( ! current_user_can( 'administrator' )) ) { |
||
| 90 | return false; |
||
| 91 | } |
||
| 92 | |||
| 93 | if ( isset( $_REQUEST['do_widget_debug'] ) ) { |
||
| 94 | if ( empty( $said ) ) { |
||
| 95 | $said = true; |
||
| 96 | } else { |
||
| 97 | return true; |
||
| 98 | } |
||
| 99 | |||
| 100 | $url_without_debug_query = esc_url( remove_query_arg( 'do_widget_debug' ) ); |
||
| 101 | $eek = '<a href="' . $url_without_debug_query . '">Remove debug</a>'; |
||
| 102 | echo '<br/>Note: Debug help is only shown to a logged-in Administrator.' |
||
| 103 | . $eek |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 104 | . '<br />'; |
||
| 105 | $text = shortcodely_show_shortcode_widget_possibilities(); |
||
| 106 | echo $text; |
||
|
0 ignored issues
–
show
|
|||
| 107 | |||
| 108 | return true; |
||
| 109 | } else { |
||
| 110 | return false; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | /*-----------------------------------*/ |
||
| 114 | /** |
||
| 115 | * @param string $type |
||
| 116 | */ |
||
| 117 | function shortcodely_show_widget_debug( $type, $name, $id, $sidebar ) { |
||
|
0 ignored issues
–
show
|
|||
| 118 | global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets, $debugcount; |
||
| 119 | // only do these debug if we are logged in and are the administrator |
||
| 120 | |||
| 121 | $debug = shortcodely_check_if_widget_debug(); |
||
| 122 | $text = shortcodely_show_shortcode_widget_possibilities(); |
||
| 123 | |||
| 124 | if ( 'empty' == $type ) { |
||
| 125 | if ( current_user_can( 'administrator' ) ) { |
||
| 126 | $text = '<p>Problem with do_widget shortcode? Try one of the following:</p>' . $text; |
||
| 127 | } |
||
| 128 | } elseif ( ('which one' == $type) and ($debug) ) { |
||
| 129 | $text = '<p>Debug help is on: Is your widget in the widgets_for_shortcodes sidebar?</p>' |
||
| 130 | . $text; |
||
| 131 | } |
||
| 132 | |||
| 133 | return $text; |
||
| 134 | } |
||
| 135 | /*-----------------------------------*/ |
||
| 136 | function shortcodely_save_shortcodes_sidebar() { |
||
| 137 | // when switching a theme, save the widgets we use for the shortcodes as they are getting overwritten |
||
| 138 | $sidebars_widgets = wp_get_sidebars_widgets(); |
||
| 139 | if ( ! empty( $sidebars_widgets['widgets_for_shortcodes'] ) ) { |
||
| 140 | update_option( 'sidebars_widgets_for_shortcodes_saved', $sidebars_widgets['widgets_for_shortcodes'] ); |
||
| 141 | } else { // our shortcodes sidebar is empty but when to fix ? |
||
| 142 | } |
||
| 143 | } |
||
| 144 | /*-----------------------------------*/ |
||
| 145 | function shortcodely_restore_shortcodes_sidebar() { |
||
| 146 | // when switching a theme, restore the widgets we use for the shortcodes as they are getting overwritten |
||
| 147 | global $_wp_sidebars_widgets; |
||
| 148 | |||
| 149 | $sidebars_widgets = wp_get_sidebars_widgets(); |
||
| 150 | if ( empty( $sidebars_widgets['widgets_for_shortcodes'] ) ) { |
||
| 151 | $sidebars_widgets['widgets_for_shortcodes'] = get_option( 'sidebars_widgets_for_shortcodes_saved' ); |
||
| 152 | update_option( 'sidebars_widgets', $sidebars_widgets ); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | /*-----------------------------------*/ |
||
| 156 | function shortcodely_upgrade_sidebar() { |
||
| 157 | // added in 2014 February for compatibility.. keep for how long. till no sites running older versions.? |
||
| 158 | $sidebars_widgets = wp_get_sidebars_widgets(); |
||
| 159 | if ( ! empty( $sidebars_widgets['Shortcodes'] ) and empty( $sidebars_widgets['widgets_for_shortcodes'] ) ) { // we need to upgrade |
||
| 160 | $sidebars_widgets['widgets_for_shortcodes'] = $sidebars_widgets['Shortcodes']; |
||
| 161 | unset( $sidebars_widgets['Shortcodes'] ); |
||
| 162 | update_option( 'sidebars_widgets', $sidebars_widgets ); |
||
| 163 | add_action( 'admin_notices', 'widgets_shortcode_admin_notice' ); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | function widgets_shortcode_admin_notice() { |
||
| 168 | ?> |
||
| 169 | <div class="updated"> |
||
| 170 | <p>Please go to widgets page and check your "widgets for shortcodelys" sidebar. It will hopefully have been corrected upgraded with your widgets and all should be fine.</p> |
||
| 171 | </div> |
||
| 172 | <?php |
||
| 173 | |||
| 174 | } |
||
| 175 | /*-----------------------------------*/ |
||
| 176 | |||
| 177 | ?> |
||
| 178 |