bws_custom_code_tab

The Google Captcha (reCAPTCHA) by BestWebSoft bws custom code tab function.

Description

bws_custom_code_tab(); 

Usage

  1. if ( !function_exists( 'bws_custom_code_tab' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-captcha-recaptcha-by-bestwebsoft/bws_menu/deprecated.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bws_custom_code_tab(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bws_menu/deprecated.php  
  1. function bws_custom_code_tab() { 
  2. if ( ! current_user_can( 'edit_plugins' ) ) 
  3. wp_die( __( 'You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft' ) ); 
  4.  
  5. global $bstwbsftwppdtplgns_options; 
  6.  
  7. $message = $content = ''; 
  8. $is_css_active = $is_php_active = false; 
  9.  
  10. $upload_dir = wp_upload_dir(); 
  11. $folder = $upload_dir['basedir'] . '/bws-custom-code'; 
  12. if ( ! $upload_dir["error"] ) { 
  13. if ( ! is_dir( $folder ) ) 
  14. wp_mkdir_p( $folder, 0755 ); 
  15.  
  16. $index_file = $upload_dir['basedir'] . '/bws-custom-code/index.php'; 
  17. if ( ! file_exists( $index_file ) ) { 
  18. if ( $f = fopen( $index_file, 'w+' ) ) 
  19. fclose( $f ); 
  20.  
  21. $css_file = 'bws-custom-code.css'; 
  22. $real_css_file = $folder . '/' . $css_file; 
  23.  
  24. $php_file = 'bws-custom-code.php'; 
  25. $real_php_file = $folder . '/' . $php_file; 
  26.  
  27. $is_multisite = is_multisite(); 
  28. if ( $is_multisite ) 
  29. $blog_id = get_current_blog_id(); 
  30.  
  31. if ( isset( $_REQUEST['bws_update_custom_code'] ) && check_admin_referer( 'bws_update_' . $css_file ) ) { 
  32.  
  33. /** CSS */ 
  34. $newcontent_css = wp_unslash( $_POST['bws_newcontent_css'] ); 
  35. if ( ! empty( $newcontent_css ) && isset( $_REQUEST['bws_custom_css_active'] ) ) { 
  36. if ( $is_multisite ) 
  37. $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] = $upload_dir['baseurl'] . '/bws-custom-code/' . $css_file; 
  38. else 
  39. $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] = $upload_dir['baseurl'] . '/bws-custom-code/' . $css_file; 
  40. } else { 
  41. if ( $is_multisite ) { 
  42. if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] ) ) 
  43. unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] ); 
  44. } else { 
  45. if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] ) ) 
  46. unset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] ); 
  47. if ( $f = fopen( $real_css_file, 'w+' ) ) { 
  48. fwrite( $f, $newcontent_css ); 
  49. fclose( $f ); 
  50. $message .= sprintf( __( 'File %s edited successfully.', 'bestwebsoft' ), '<i>' . $css_file . '</i>' ) . ' '; 
  51. } else { 
  52. $error .= __( 'Not enough permissions to create or update the file', 'bestwebsoft' ) . ' ' . $real_css_file . '. '; 
  53.  
  54. /** PHP */ 
  55. $newcontent_php = wp_unslash( trim( $_POST['bws_newcontent_php'] ) ); 
  56. if ( file_exists( $index_file ) ) { 
  57. if ( ! empty( $newcontent_php ) && isset( $_REQUEST['bws_custom_php_active'] ) ) { 
  58. if ( $is_multisite ) 
  59. $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] = $real_php_file; 
  60. else 
  61. $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] = $real_php_file; 
  62. } else { 
  63. if ( $is_multisite ) { 
  64. if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] ) ) 
  65. unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] ); 
  66. } else { 
  67. if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] ) ) 
  68. unset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] ); 
  69.  
  70. if ( $f = fopen( $real_php_file, 'w+' ) ) { 
  71. $newcontent_php = $newcontent_php; 
  72. fwrite( $f, $newcontent_php ); 
  73. fclose( $f ); 
  74. $message .= sprintf( __( 'File %s edited successfully.', 'bestwebsoft' ), '<i>' . $php_file . '</i>' ); 
  75. } else { 
  76. $error .= __( 'Not enough permissions to create or update the file', 'bestwebsoft' ) . ' ' . $real_php_file . '. '; 
  77. } else { 
  78. $error .= __( 'Not enough permissions to create the file', 'bestwebsoft' ) . ' ' . $index_file . '. '; 
  79.  
  80. if ( ! empty( $error ) ) 
  81. $error .= ' <a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">' . __( 'Learn more', 'bestwebsoft' ) . '</a>'; 
  82.  
  83. if ( $is_multisite ) 
  84. update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  85. else 
  86. update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  87.  
  88. if ( file_exists( $real_css_file ) ) { 
  89. update_recently_edited( $real_css_file ); 
  90. $content_css = esc_textarea( file_get_contents( $real_css_file ) ); 
  91. if ( ( $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] ) ) || 
  92. ( ! $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] ) ) ) { 
  93. $is_css_active = true; 
  94. if ( file_exists( $real_php_file ) ) { 
  95. update_recently_edited( $real_php_file ); 
  96. $content_php = esc_textarea( file_get_contents( $real_php_file ) ); 
  97. if ( ( $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] ) ) || 
  98. ( ! $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] ) ) ) { 
  99. $is_php_active = true; 
  100. } else { 
  101. $content_php = "<?php" . "\n" . "if ( ! defined( 'ABSPATH' ) ) exit;" . "\n" . "if ( ! defined( 'BWS_GLOBAL' ) ) exit;" . "\n\n" . "/* Start your code here */" . "\n"; 
  102.  
  103. if ( ! empty( $message ) ) { ?> 
  104. <div id="message" class="below-h2 updated notice is-dismissible"><p><?php echo $message; ?></p></div> 
  105. <?php } ?> 
  106. <form action="" method="post"> 
  107. <?php foreach ( array( 'css', 'php' ) as $extension ) { ?> 
  108. <p> 
  109. <?php if ( 'css' == $extension ) 
  110. _e( 'These styles will be added to the header on all pages of your site.', 'bestwebsoft' ); 
  111. else 
  112. printf( __( 'This PHP code will be hooked to the %s action and will be printed on front end only.', 'bestwebsoft' ), '<a href="http://codex.wordpress.org/Plugin_API/Action_Reference/init" target="_blank"><code>init</code></a>' ); ?> 
  113. </p> 
  114. <p><big> 
  115. <?php if ( ! file_exists( ${"real_{$extension}_file"} ) || ( is_writeable( ${"real_{$extension}_file"} ) ) ) { 
  116. echo __( 'Editing', 'bestwebsoft' ) . ' <strong>' . ${"{$extension}_file"} . '</strong>'; 
  117. } else { 
  118. echo __( 'Browsing', 'bestwebsoft' ) . ' <strong>' . ${"{$extension}_file"} . '</strong>'; 
  119. } ?> 
  120. </big></p> 
  121. <p><label><input type="checkbox" name="bws_custom_<?php echo $extension; ?>_active" value="1" <?php if ( ${"is_{$extension}_active"} ) echo "checked"; ?> /> <?php _e( 'Activate', 'bestwebsoft' ); ?></label></p> 
  122. <textarea cols="70" rows="25" name="bws_newcontent_<?php echo $extension; ?>" id="bws_newcontent_<?php echo $extension; ?>"><?php if ( isset( ${"content_{$extension}"} ) ) echo ${"content_{$extension}"}; ?></textarea> 
  123. <p class="description"> 
  124. <a href="<?php echo ( 'css' == $extension ) ? 'https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started' : 'http://php.net/' ?>" target="_blank"> 
  125. <?php printf( __( 'Learn more about %s', 'bestwebsoft' ), strtoupper( $extension ) ); ?> 
  126. </a> 
  127. </p> 
  128. <?php } 
  129. if ( ( ! file_exists( $real_css_file ) || is_writeable( $real_css_file ) ) && ( ! file_exists( $real_php_file ) || is_writeable( $real_php_file ) ) ) { ?> 
  130. <p class="submit"> 
  131. <input type="hidden" name="bws_update_custom_code" value="submit" /> 
  132. <?php submit_button( __( 'Save Changes', 'bestwebsoft' ), 'primary', 'submit', false ); 
  133. wp_nonce_field( 'bws_update_' . $css_file ); ?> 
  134. </p> 
  135. <?php } else { ?> 
  136. <p><em><?php printf( __( 'You need to make this files writable before you can save your changes. See %s the Codex %s for more information.', 'bestwebsoft' ),  
  137. '<a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">',  
  138. '</a>' ); ?></em></p> 
  139. <?php } ?> 
  140. </form> 
  141. <?php }